Reputation: 21490
I used the SystemEnvironment class in Java for getting system information.
In that I can get only RAM size, I can't get the specific disk space like c: and D:
code is,
com.sun.management.OperatingSystemMXBean mxbean = (com.sun.management.OperatingSystemMXBean)ManagementFactory.getOperatingSystemMXBean(); System.out.println("Total RAM:"+mxbean.getTotalSwapSpaceSize()/(1024*1024*1024)+""+"GB");
Can i get this in information in a Java program?
Upvotes: 1
Views: 402
Reputation: 383966
From java.io.File
API:
long getTotalSpace()
: Returns the size of the partition named by this abstract pathname.long getUsableSpace()
: Returns the number of bytes available to this virtual machine on the partition named by this abstract pathname.long getFreeSpace()
: Returns the number of unallocated bytes in the partition named by this abstract path name.The following snippet shows an example on how to use it:
for (File root : File.listRoots()) {
System.out.format("%s (%d bytes free)%n", root, root.getFreeSpace());
}
Upvotes: 9