file.listRoots不适用于Java中的便携式USB驱动器

file.listRoots不适用于Java中的便携式USB驱动器,java,usb-drive,usb4java,jmtp,Java,Usb Drive,Usb4java,Jmtp,对于内部文件驱动器信息,file.listRoots工作正常,但无法获取USB和便携文件信息。这是我的密码: File[] paths; try { // returns pathnames for files and directory paths = File.listRoots(); for (File path : paths) // for each pathname in pathname array System.out.println(p

对于内部文件驱动器信息,file.listRoots工作正常,但无法获取USB和便携文件信息。这是我的密码:

File[] paths; 
try {
    // returns pathnames for files and directory
    paths = File.listRoots();
    for (File path : paths) // for each pathname in pathname array
        System.out.println(path); // prints file and directory paths
} catch(Exception e) { // if any error occurs
    e.printStackTrace();
}

我不明白为什么我的便携式USB信息无法获取?

如果您的USB驱动器已连接且可访问,您可以检查NIO代码是否显示以下卷:

for (Path root : FileSystems.getDefault().getRootDirectories()) {
    FileStore fs = Files.getFileStore(root);
    System.out.format("FileStore %s\tName: '%s'\tType: %s%n", root, fs.name(), fs.type());
    System.out.println();
}
在上述循环中,您还可以检查其他文件系统属性,如removable storage flag:

String[] attrs = new String[]{"volume:isRemovable"};

for (String s : attrs) {
    System.out.format("\t%s=%s", s, fs.getAttribute(s));
}

你得到了什么输出,在什么操作系统上,这个问题与javafx有什么关系?我只得到像C,D这样的桌面驱动器,没有得到usb信息,window10,我在javafx项目中使用这个代码这个普通的java,与fx无关-请删除javafx标记我用过这个,但再次只显示C,D,E驱动器不是我连接的usb设备您的驱动器是否在Windows资源管理器中分配或映射了驱动器号?如果没有,则此代码将不会有帮助。我的设备驱动器名是Moto。解决方案是什么?一些手机/平板电脑会公开其光盘,以便Windows驱动器映射工作,并且您可以通过Java轻松地读/写。不过,听起来您的设备可能使用媒体传输协议,您需要使用支持MTP的客户端Windows Explorer就是这样一个应用程序。这里已经提到了这个话题[