Cross platform, Java 1.6:
java
File[] roots = File.listRoots();
for (File root : roots) {
double usedSpace = (double)(root.getTotalSpace() - root.getUsableSpace())/root.getTotalSpace();
System.out.format("%s: %.1f used of %s%n",
root.getAbsolutePath(), usedSpace, FormatUtil.formatBytes(root.getTotalSpace()));
}
该提问来源于开源项目:oshi/oshi