This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am programming in Java 1.6, running on a Fedora 7 Linux system. I need to be able to find the disk drives in the system programmatically. Is there a straightforward way to do this in Java? (Sorry, I'm not sure if this belongs in a Java forum or Linux forum).
Via the Linux command line, I've found that I can run the command "cat /proc/scsi/sg/device_strs", which gives me a list of not only my disk drives, but also my dvd-rom. I can parse that output, looking for the string "ATA" to find the disk drive, that position in the list will relate to the number in the /dev/sg? list (zero-based) - for example I have three entries listed as ATA, ATA, and non-ATA, which relate to /dev/sg0, /dev/sg1, and /dev/sg2 respectively. I know that the /dev/sg0 and /dev/sg1 devices are my disk drives since they are listed as ATA.
That approach is certainly doable by running system commands with Java and parsing the results. Before I go down that path, I want to be sure there isn't an easier way to accomplish the same thing. Or if there is no support with Java itself, perhaps there is a better way using Linux commands to get the same information.