Java计算磁盘的大小

源代码如下:

 1 import java.io.File;
 2 public class SpaceChecker
 3 {
 4      public static void main(String [] args)
 5      {
 6           File[] roots=File.listRoots();
 7            for(File  _file:roots)
 8             {
 9                   System.out.println(_file.getPath());
10                   System.out.println(_file.getName()); 
11                   System.out.println("可用空间:"+_file.getFreeSpace());
12                   System.out.println("已用空间:"+_file.getUsabelSpace());
13                   System.out.println("总空间:"+_file.getTotalSpace());
14              }
15        File win=new File("C:\\WINDOWS");
16        System.out.println(win.getPath());
17        System.out.println(win.getName());
18 System.out.println("可用空间:"+win.getFreeSpace()); 19 System.out.println("已用空间:"+win.getUsabelSpace()); 20 System.out.println("总空间:"+win.getTotalSpace()); 21 System.out.println(); 22 } 23 }

 

posted @ 2012-04-16 15:50  json_chan  阅读(975)  评论(1编辑  收藏  举报