Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get list of all drives but also get the corresponding drive type (removable,local disk, or cd-rom,dvd-rom... etc)?

Tags:

How can I get list all drives but also get the corresponding drive type (removable, local disk, or cd-rom, dvd-rom, etc)?

like image 721
xolmc Avatar asked Aug 22 '10 15:08

xolmc


People also ask

How do I find the D drive on my computer?

Right-click Computer > Manage > Storage > Disk Management, then right-click on the graphic of the drive that may be 'hidden' or 'unallocated' > Change Drive Letter/Paths... > select a letter from nearer the end of the alphabet > OK and the disk should show in Computer. Good luck. Was this reply helpful?

How do I get drives in Java?

In Java, you use the File. listRoots() to list all the available drives of your computer. listRoots() is a static method in File class which return the array of available filesystem roots. To get the type of drive, you use the getSystemTypeDescription(File f) method of FileSystemView class.

How do you find D drive on Windows 10?

Drive D:\ and External Drives can be found in File Explorer. Right click the Window icon on the bottom left and select File Explorer then click This PC. If Drive D:\ is not there, most probably you haven't partition your hard drive and to partition the Hard drive you can do that in Disk Management.


2 Answers

With this code you can get all drives and its type description

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)); } 
like image 151
pafivi Avatar answered Oct 08 '22 08:10

pafivi


Assuming it's windows, use File.listRoots() to get all roots. Then use FileSystemView to check whether it's floppy disk or a drive. Other than that I have no idea.

like image 34
Louis Rhys Avatar answered Oct 08 '22 08:10

Louis Rhys