public class Diskfree {
public static void main(String[] args) {
File[] roots = File.listRoots();//获取磁盘分区列表
for (File file : roots) {
System.out.println(file.getPath() + "信息如下:");
System.out.println("空闲未使用 = " + file.getFreeSpace() / 1024 / 1024 / 1024 + "G");//空闲空间
System.out.println("已经使用 = " + file.getUsableSpace() / 1024 / 1024 / 1024 + "G");//可用空间
System.out.println("总容量 = " + file.getTotalSpace() / 1024 / 1024 / 1024 + "G");//总空间
System.out.println();
}
}
}