Java 7の新しいファイル システム APIは、これを行うことができます。
FileSystem fs = FileSystems.getDefault();
for (Path rootPath : fs.getRootDirectories())
{
try
{
FileStore store = Files.getFileStore(rootPath);
System.out.println(rootPath + ": " + store.type());
}
catch (IOException e)
{
System.out.println(rootPath + ": " + "<error getting store details>");
}
}
私のシステムでは、次のようになりました(ドライブDにCDがあり、残りのハードディスクまたはネットワーク共有があります):
C:\: NTFS
D:\: CDFS
H:\: NTFS
M:\: NTFS
S:\: NTFS
T:\: NTFS
V:\: <error getting store details>
W:\: NTFS
Z:\: NTFS
したがって、ファイル ストアのtype()に対するクエリで実行する必要があります。
ドライブに CD がない場合、getFileStore() 呼び出しがスローされます。
java.nio.file.FileSystemException: D:: デバイスの準備ができていません。