获取磁盘信息

Java代码如下

public class DiskInfo {

    public void queryDiskInfo() {

        FileSystemView fileSystemView = FileSystemView.getFileSystemView();

        File[] files = File.listRoots();
        for (File file : files) {
            String name = fileSystemView.getSystemDisplayName(file);
            long totalSpace = file.getTotalSpace();
            long freeSpace = file.getFreeSpace();

            System.out.println(name+"  "+totalSpace+"  "+freeSpace);

        }


    }
}
原文地址:https://www.cnblogs.com/AyasatoMayoi/p/11041426.html