In this example we will show the method to get free disk space in Java.
Source Code
package com.beginner.examples;
import java.io.*;
public class GetFreeDisk {
public static void main(String[] args) throws IOException{
File file = new File("c:");
// get free disk space
long total = file.getTotalSpace();
long usable = file.getUsableSpace();
System.out.println("Total size : " + total/1024/1024/1024 + " GB");
System.out.println("Usable size : " + usable/1024/1024/1024 + " GB");
}
}
Output:
Total size : 172 GB
Usable size : 90 GB