java - 在Java中获取驱动器数量

标签 java drive

我有一个非常简单的问题。

如何在 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/

相关文章:

java - 出现类似java.lang.String的错误不是double模式的有效外部类型在下面的代码中

c++ - 尝试编写一个综合方法来使用 C++ 确定 Windows 驱动器类型

javascript - 通过 GAS 将存储在云端硬盘文件夹中的图像添加到 Google 文档

java - 获取 Mac 中运行的驱动程序

java - Burrows Wheeler 变换的优化

java - 注入(inject)一个为 ProjectDao 提供服务的类

java - 配置Elasticsearch到java SpringBoot应用程序

java - 网页无法使用 JEdior Pane 运行

r - 通过网络复制文件 `file.copy` 比 `system(mv ...)` 慢得多

google-apps-script - 自动查找并永久删除Google云端硬盘中的垃圾项目