1
File f=new File("D://java");
long totalInBytes=f.getTotalSpace();
long freeInBytes=f.getFreeSpace();
long totalInGB=totalInBytes/(1024*1024*1024);
long freeInGB=freeInBytes/(1024*1024*1024);
long used=totalInGB-freeInGB;
System.out.println(used);

I have tried above code but it is giving size of D: drive but not java folder.

  • Have you read the `File` javadoc? – Sotirios Delimanolis Sep 25 '14 at 15:00
  • As far as I know, such information cannot be retrieved directly from all operating systems directly thus no standard java method can give you O(1) time for that. Best way is to perform summing of file lengths within directory (as specified by question linked by @Benjamin). Other than that, you're left with OS-specific external libraries. – initramfs Sep 25 '14 at 15:02
  • Thanks for your reply. I got solution `long size = FileUtils.sizeOfDirectory(new File("D://Java")); long ac=size/(1024*1024); System.out.println("Folder Size: " + ac +" MB");` – user3914167 Sep 25 '14 at 15:19

0 Answers0