How to calculate available disk space in linux machine using java? [duplicate]
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?
精彩评论