java - 在 MacOS 上列出外部驱动器时出现 java 错误
问题描述
我正在尝试列出计算机中的所有驱动器,包括附加的驱动器。
FileStore fileStore = null;
try {
fileStore = Files.getFileStore(root);
System.out.format("%s\t%s\n", root, fileStore.getAttribute("volume:isRemovable"));
} catch (IOException e) {
e.printStackTrace();
}
}```
I tried the above code but I am receiving the following error when I have an external USB drive attached:
java.lang.UnsupportedOperationException: 'volume:isRemovable' not recognized
at sun.nio.fs.UnixFileStore.getAttribute(UnixFileStore.java:150)
at com.roscasend.javacore.utils.FileUtilities.listComputerDrives(FileUtilities.java:27)
Best Regards,
Aurelian
解决方案
我找到了以下答案,它帮助我显示了来自 mac os 计算机的所有驱动器:
File [] osxVols = new File("/Volumes").listFiles();
for(int i=0; i<osxVols.length; i++) {
map.put(osxVols[i].getAbsolutePath(), osxVols[i].getName());
}```
推荐阅读
- windows - 不显示消息框 MessageBoxA()
- node.js - javascript函数设置的表单字段值的req.body值未定义
- facebook - Facebook 在验证用户 Rails 后重定向到注册页面
- angular - Angular - 视图绑定到数组未更新
- android - Firebase ML-Kit 多检测器
- angularjs - Angular Summernote 不适用于 webpack?
- kubernetes-helm - 如何在 helm 模板中的属性名称中使用冒号访问属性
- cassandra - Nodetool 修复 - 如何在 linux 上自动化和修复期间的操作
- arrays - 连接四个游戏
- r - GGplot 2堆积条似乎随机排序