H5W3
当前位置:H5W3 > 其他技术问题 > 正文

java计算磁盘空间的大小

    java计算磁盘空间的大小,jdk1.6下通过。

import java.io.File;
 
 public class SpaceChecker {
     public static void main(String[] args) {
         File[] roots = File.listRoots();
         for (File _file : roots) {
             System.out.println(_file.getPath());
             //System.out.println(_file.getName());
             System.out.println("Free space = " + _file.getFreeSpace());
             System.out.println("Usable space = " + _file.getUsableSpace());
             System.out.println("Total space = " + _file.getTotalSpace());
             System.out.println();
         }
         
         
         File win = new File("C:\\WINDOWS");
         System.out.println(win.getPath());
         System.out.println(win.getName());
         System.out.println("Free space = " + win.getFreeSpace());
         System.out.println("Usable space = " + win.getUsableSpace());
         System.out.println("Total space = " + win.getTotalSpace());
         System.out.println();
     }
 }
运行结果:

D:\java>java SpaceCheckerA:\Free space = 0Usable space = 0Total space = 0

C:\Free space = 995975168Usable space = 995975168Total space = 4301590528

D:\Free space = 4041146368Usable space = 4041146368Total space = 10756333568

E:\Free space = 10000908288Usable space = 10000908288Total space = 26012024832

F:\Free space = 0Usable space = 0Total space = 0

C:\WINDOWSWINDOWSFree space = 995975168Usable space = 995975168Total space = 4301590528

 

本文地址:H5W3 » java计算磁盘空间的大小

评论 0

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址