我有一个非常简单的问题。
如何在 Java 中找到系统连接驱动器的数量?
另外,我如何确定这些是 HDD、SSD 还是 USB?
最佳答案
没有独立于系统的方法来区分 HDD 和 SDD,尽管您可能可以从驱动器的名称中猜测出来。您能做的最好的事情就是使用 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 ) );
}
关于java - 在Java中获取驱动器数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29106082/