1

I have a pretty simple question.

How can I find the number of system-attached drives in Java?
Also, how can I determine if these are HDDs, SSDs, or USBs?

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Zulfe
  • 820
  • 7
  • 25
  • Possible duplicate: http://stackoverflow.com/questions/21985034/how-to-find-out-operating-system-drive-using-java – Masudul Mar 17 '15 at 17:44

1 Answers1

1

There is no system-independent way to tell the difference between, say, an HDD and an SDD, though you might be able to guess from the name of the drive. The best you can do is use FileSystemView:

File[] paths;
FileSystemView fsv = FileSystemView.getFileSystemView();

// returns pathnames for files and directory
paths = File.listRoots();

// for each pathname in pathname array
for (File path : paths) {
    // prints file and directory paths
    System.out.println( "Drive Name: " + path );
    System.out.println( "Description: " + fsv.getSystemTypeDescription(path) );
    System.out.println( "Type: " + fsv.getSystemTypeDescription( path ) );
    System.out.println( "Is Drive? " + fsv.isDrive( path ) );
}
Tom
  • 16,842
  • 17
  • 45
  • 54
Tyler Durden
  • 11,156
  • 9
  • 64
  • 126