1.WatchFile类实现Runnable接口
public class WatchFile implements Runnable{
@Override
public void run() {
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”);
}
}
“
2.Test类
public class Test {
public static void main(String[] args) {
do{
WatchFile wf = new WatchFile();
Thread th = new Thread(wf);
th.start();
try {
System.out.println(“每隔三秒监控——”);
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}while(true);
}
}
实现每隔三秒监控C盘空间
磁盘内存实时监控
最新推荐文章于 2023-06-01 10:06:47 发布