Java free disk space
366 viewsA request I got from a member on our forum to write an example to get the total and free diskspace left on the local harddisk. Note: Java SE 1.6 is required to run the sourcecode.
Output:
Java free diskspace demo
c:\ 111,79 Gb total 13,39 Gb left
d:\ 0,00 Gb total 0,00 Gb left
e:\ 0,00 Gb total 0,00 Gb left
f:\ 0,00 Gb total 0,00 Gb left
g:\ 0,00 Gb total 0,00 Gb left
h:\ 0,48 Gb total 0,01 Gb left
JAVA:
-
/*--------------------------------------------------------------------------
-
DiskSpaceDemo class
-
*****************
-
By: HapyFace http://www.engineeringserver.com - http://www.javaforums.net
-
Contact: info [@] engineeringserver.com
-
Version: 17/August/2008
-
Last updated: 17/August/2008
-
*****************
-
Note: a demo that shows the freediskspace of several local harddisks.
-
//----------------------------------------------------------------------*/
-
import java.io.File;
-
import java.text.DecimalFormat;
-
-
public class DiskSpaceDemo {
-
-
for(int i = 0; i <diskDrive.length; i++){
-
System.out.println(diskDrive[i] + " " + diskTotal.format(f.getTotalSpace()/1024/1024/1024d) + " " + diskLeft.format((f.getFreeSpace()/1024/1024/1024d)));
-
}
-
}
-
}













