Finds out total usable space available in a partition using java
The getUsableSpace method of File class can be used for getting the total usable space available in a partition or drive using java.
import java.io.File;
/**
* File class examples.
*
*/
public class FileExample {
public static void main(String[] args){
// Create file object representing the source file/directory
File file = new File("d:\\temp\\test.txt");
// Get the total usable space available in current drive
long value = file.getUsableSpace();
// Convert it to GigaBytes
double valueGB = (double) value / 1024 / 1024 / 1024;
System.out.println("Total free space available in the current partition is "+valueGB);
}
}




















