java监测硬盘空间大小

package com.zuidaima.util.file;
 
import java.io.File;
 
public class FreeDiskSpace {
 
    public static void main(String[] args) {
        File file = new File("c:");
        long totalSpace = file.getTotalSpace();
        long freeSpace = file.getFreeSpace();
        long usedSpace = totalSpace - freeSpace;
 
        System.out.println("总空间大小 : " + totalSpace / 1024 / 1024 / 1024 + "G");
        System.out.println("剩余空间大小 : " + freeSpace / 1024 / 1024 / 1024 + "G");
        System.out.println("已用空间大小 : " + usedSpace / 1024 / 1024 / 1024 + "G");
    }
 
}

 

posted @ 2018-07-11 10:11  小泉哥  阅读(1693)  评论(0编辑  收藏  举报