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");
    }
 
}

猜你喜欢

转载自www.cnblogs.com/penghq/p/9293038.html