A blog by a system administrator and programmer.

Java disk usage 
Friday, January 11, 2008, 11:56 AM - Programming
Posted by Freddy Chu
It have been a long time for me to found a way to check the disk usage in Java.

Finially i get the solutions. It is in Java 6.0. java.io.File

There is 2 functions.

getTotalSpace() --- Returns the size of the partition named by this abstract pathname.
getUsableSpace() --- Returns the number of bytes available to this virtual machine on the partition named by this abstract pathname.


If your application is limited to use versions before 6.0. Then you can only keep using external commands.
Runtime.getRuntime().exec(commands);
e.g.
Linux/Unix: df
Windows: fsutil volume diskfree c:

Alternative solutions for system independent solutions is to setup a snmp on the server you want to check and use java snmp client to query the result. That will be quite complex.

Useful links:
snmp4j
netsnmp
add comment ( 125 views )   |  permalink   |   ( 3 / 3840 )

<<First <Back | 1 | 2 | Next> Last>>