I’m running Java on a Unix platform. How can I get a list of all mounted filesystems via the Java 1.6 API?
I’ve tried File.listRoots() but that returns a single filesystem (that is, /). If I use df -h I see more than that:
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/disk0s2 931Gi 843Gi 87Gi 91% 221142498 22838244 91% /
devfs 187Ki 187Ki 0Bi 100% 646 0 100% /dev
map -hosts 0Bi 0Bi 0Bi 100% 0 0 100% /net
map auto_home 0Bi 0Bi 0Bi 100% 0 0 100% /home
/dev/disk1s2 1.8Ti 926Gi 937Gi 50% 242689949 245596503 50% /Volumes/MyBook
/dev/disk2 1.0Gi 125Mi 875Mi 13% 32014 223984 13% /Volumes/Google Earth
I would expect to see /home as well (at a minimum).
Java doesn’t provide any access to mount points. You have to run system command
mountviaRuntime.exec()and parse its output. Either that, or parse the contents of/etc/mtab.