如何使用Java获取Linux中的总磁盘空间?

前端之家收集整理的这篇文章主要介绍了如何使用Java获取Linux中的总磁盘空间?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我可以获得可用磁盘空间.我如何获得总磁盘空间?

我的代码是:

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没有磁盘总空间的方法???希望你的回复

提前致谢

最佳答案
尝试

  System.out.println(new File("/").getTotalSpace()/1024/1024/1024); //in GB
原文链接:https://www.f2er.com/linux/440267.html

猜你在找的Linux相关文章