weixin_39970823 2020-11-30 12:42
浏览 0

Add disk usage information

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

  • 写回答

7条回答 默认 最新

  • weixin_39970823 2020-11-30 12:42
    关注

    See http://stackoverflow.com/questions/462110/acquiring-drive-names-as-opposed-to-drive-letters-in-java for more useful drive names and descriptions (probably use root.toString() as a fallback for an empty name). This works well for Windows, but only gives "/" in Mac/Linux so will need platform-specific implementations.

    评论

报告相同问题?