fork(1) download
  1. import java.io.File;
  2.  
  3. public class Main {
  4.  
  5. private static long GB = 1000 * 1000 * 1000;
  6. private static long GiB = 1024 * 1024 * 1024;
  7.  
  8. private static void printGB(long bytes) {
  9. System.out.printf("%.2f GB\n", (double) bytes / GB);
  10. }
  11.  
  12. private static void printGiB(long bytes) {
  13. System.out.printf("%.2f GiB\n", (double) bytes / GiB);
  14. }
  15.  
  16. public static void main(String[] args) {
  17. File[] roots = File.listRoots();
  18. long free_space = 0;
  19. for (int i = 0; i < roots.length; i++)
  20. free_space += roots[i].getFreeSpace();
  21. printGiB(free_space);
  22. printGB(free_space);
  23. }
  24. }
Success #stdin #stdout 0.08s 381248KB
stdin
Standard input is empty
stdout
229.87 GiB
246.82 GB