开发者

How to calculate available disk space in linux machine using java? [duplicate]

开发者 https://www.devze.com 2023-01-24 18:04 出处:网络
This question already has answers here: How to find how much disk space is left using Java? (4 answers)
This question already has answers here: How to find how much disk space is left using Java? (4 answers) Closed 5 years ago. 开发者_如何学JAVA

I tried with File getFreeSpace() also which returns me 0. Is there any other way to do this?


How about the older org.apache.commons.io.FileSystemUtils?


try {

    double freeDiskSpace = org.apache.commons.io.FileSystemUtils.freeSpaceKb("/volume"); 
    double freeDiskSpaceGB = freeDiskSpace / 1024 / 1024;
    System.out.println("Free Disk Space (GB):" + freeDiskSpaceGB);

    } catch (IOException e) {
            e.printStackTrace();
    }


Try

System{" df -k | awk '{sum += $4 }i; END {print sum} '"};


public long getTotalSpace();
public long getFreeSpace();
public long getUsableSpace();

Each of these methods returns the requested size, in bytes, of the partition represented by the java.io.File or 0L if a partition cannot be obtained from the File object. Can you report your code?

0

精彩评论

暂无评论...
验证码 换一张
取 消