ошибка java при перечислении внешнего диска в macOS

#java #nio

#java #nio

Вопрос:

Я пытаюсь перечислить все диски с компьютера, включая подключенные.

             FileStore fileStore = null;
            try {
                fileStore = Files.getFileStore(root);
                System.out.format("%st%sn", 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
  

Ответ №1:

Я нашел следующий ответ, который помог мне отобразить все диски с компьютера Mac os:

     File [] osxVols = new File("/Volumes").listFiles();
    for(int i=0; i<osxVols.length; i  ) {
        map.put(osxVols[i].getAbsolutePath(), osxVols[i].getName());
    }```