如何使用Java在Linux中获取总磁盘空间? [英] How to get total disk space in Linux with Java?
本文介绍了如何使用Java在Linux中获取总磁盘空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我能够获得可用的磁盘空间.我将如何获得总磁盘空间?
I am able to get free disk space. How would I get the total disk space?
我的代码是:
import java.io.IOException;
import org.apache.commons.io.FileSystemUtils;
public class DiskSpace {
public static void main(String[] args) {
try {
//calculate free disk space
double freeDiskSpace = FileSystemUtils.freeSpaceKb(args[0]);
System.out.println(args[0]);
//convert the number into gigabyte
double freeDiskSpaceGB = freeDiskSpace / 1024 / 1024;
System.out.println("Free Disk Space (GB):" + freeDiskSpaceGB);
} catch (IOException e) {
e.printStackTrace();
}
}
}
FileSystemUtils
没有磁盘总空间的方法?希望您的答复
FileSystemUtils
do not have method for total space of disk ??? hopes for your reply
预先感谢
推荐答案
尝试
System.out.println(new File("/").getTotalSpace()/1024/1024/1024); //in GB
这篇关于如何使用Java在Linux中获取总磁盘空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文