I am able to get free disk space. How would I get the total disk space?
My code is:
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
do not have method for total space of disk ??? hopes for your reply
Thanks in advance
If you're using Java6 the File class will do:
public long getTotalSpace()
public long getFreeSpace()
public long getUsableSpace()
try
System.out.println(new File("/").getTotalSpace()/1024/1024/1024); //in GB
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With