Saturday, June 21, 2008

Disk Space Check

Take care of disk space when you are writing a big program :). Use JDK 6 features:

import java.io.File;

public class DiskSpaceCheck {
public DiskSpaceCheck() {
File file = new File("E:");
System.out.println("E:");
System.out.println("Total: " + file.getTotalSpace());
System.out.println("Free: " + file.getFreeSpace());
System.out.println("Usable: " + file.getUsableSpace());

file = new File("E://movie");
System.out.println("E://movie");
System.out.println("Total: " + file.getTotalSpace());
System.out.println("Free: " + file.getFreeSpace());
System.out.println("Usable: " + file.getUsableSpace());

file = new File("/");
System.out.println("n/");
System.out.println("Total: " + file.getTotalSpace());
System.out.println("Free: " + file.getFreeSpace());
System.out.println("Usable: " + file.getUsableSpace());
}

public static void main(String[] args) {
new DiskSpaceCheck();
}
}

I was actually very suprised that why this feature came so late.

1 comment:

Unknown said...

I was very surprised too. Looking for disk usage feature couple of time but while found it here, was surprised! ;-D