Apache Commons IO is a java library with simple IO utilities and filters.
This requires the library commons-io-2.1.jar to be in classpath.
The following example shows using FileSystemUtils.freeSpaceKb() API.
It returns the free space on a drive or volume in kilobytes.
File file = new File("C:/Test/Test.java");
System.out.println("Free space of the drive containing file [" + file + "] : " +
FileSystemUtils.freeSpaceKb(file.getAbsolutePath()) + " KB");
//Get the disk size of drive containing working directory (Its C:\ drive in my case)
System.out.println("Current drive free space : " + FileSystemUtils.freeSpaceKb() + " KB");
}
}
It gives the following output,
Drive [C:] free space : 44242924 KB
Free space of the drive containing file [C:\Test\Test.java] : 44242924 KB
Current drive free space : 44242924 KB