joy-cs
joy-cs

Reputation: 359

GetDriveType() equivalent in Java

Is there any method which performs similar tasks to the GetDriveType() method of Microsoft Visual C++. I've already gone through the FileSystemView class of Java Swing. But the method available there are limited and does not fulfill my requirement.

So please tell me someone if Java defines any such method for Windows platform or Platform Independent.

Upvotes: 0

Views: 409

Answers (2)

Vighanesh Gursale
Vighanesh Gursale

Reputation: 921

You can use File.listRoots() method. It will list all the drives in your system.

And to get detail information about that drive you can use the following code.

List roots = Arrays.asList(File.listRoots());
for(File f:roots)
{
String s = FileSystemView.getFileSystemview().getSystemTypeDescription(f);
}

This code shows the actual information of drives and other PnP devices. Use this link to know more. And according to your question you must be want to know the hardware details of connected drives to PC. Use JNI if you want to do all code in java.

Upvotes: 2

Rui Vieira
Rui Vieira

Reputation: 5328

Are you using JDK7?

If so, there is FileStore which returns the type as a String.

However, looking at the source code itself (FileStore.java) there is a warning that the return value might be implementation specific.

Upvotes: 1

Related Questions