Calculating free disk space using Apache Commons I in JAVA
import java.io.IOException; import org.apache.commons.io.FileSystemUtils; public class DiskSpace { public static void main(String[] args) { try { double freeDiskSpace = FileSystemUtils.freeSpaceKb("C:"); // to calculate free disk space in the system //convert the number into Gigabytes double freeDiskSpaceGB = freeDiskSpace / 1024 / 1024; System.out.println("Free Disk Space (GB):" + freeDiskSpaceGB); } catch (IOException e) { e.printStackTrace(); } } }