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.