Reputation: 3465
Is there any way to read volume label in Java program on Linux?
I've found sample of doing that at http://www.rgagnon.com/javadetails/java-0455.html It uses FileSystemView class, but it seems working only on Windows. On Linux for /dev/sdb1 it returns sdb1.
Upvotes: 2
Views: 1182
Reputation: 8474
There does not seem to exist portable way to do it in java. You will need to write separate code for each OS.
For linux you will need to run proper system command depending on filesystem type and then parse the output.
To read label from cdrom:
$ volname /dev/cdrom
Ubuntu 10.10 i386
To read label from ntfs partition (-f
needed for mounted filesystem):
$ ntfslabel -f /dev/sda5 2>/dev/null
DATA
To read FAT (vfat) label:
dosfslabel /dev/sdb
SD card
Note: You will need read permissions for devices you're accessing.
Upvotes: 2