'I only want to get a hard disk path from Java
I only want to get a path from Java that is a hard disk, not a network disk or usb. I used FileSystemView but it wasn't useful. How can I get disk list? ex) I have C drive, D drive, H USB, but I only want to get C and D
File[] drives = File.listRoots();
if (drives != null && drives.length > 0) {
for (File aDrive : drives) {
FileSystemView fsv = FileSystemView.getFileSystemView();
String driveType = fsv.getSystemTypeDescription(aDrive);
if(fsv.isFileSystemRoot(aDrive)) {
System.out.println("aDrive => " + aDrive + " : driveType => " + driveType + " ***");
} else {
System.out.println("aDrive => " + aDrive + " : driveType => " + driveType);
}
}
}
Solution 1:[1]
try this
for (FileStore fs: FileSystems.getDefault().getFileStores()) {
if (fs.type().equals("NTFS")) {
System.out.println(fs);
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | dangerousmanleesanghyeon |
