Java: how to determine the type of drive a file is located on?

mstrap picture mstrap · Feb 6, 2012 · Viewed 9.7k times · Source

Is there a platform-independent way with Java to detect the type of drive a file is located on? Basically I'm interested to distinguish between: hard disks, removable drives (like USB sticks) and network shares. JNI/JNA solutions won't be helpful. Java 7 can be assumed.

Answer

Mengyu ZHang picture Mengyu ZHang · Mar 26, 2013

You could execute cmd using Java with:

fsutil fsinfo drivetype {drive letter}

The result will give you something like this:

C: - Fixed Drive
D: - CD-ROM Drive
E: - Removable Drive
P: - Remote/Network Drive