• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to figure out total disk size in Java?

 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried new File(C .length(), but it returns 0. Is there any other method? If there is a method to figure out free space, then it will be great. Currently I run df from Java and then parse result. Since shells can be different this approach isn't well reliable. It won't work for other OSes like Windows, or Mac.
 
Stuart Gray
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is the best you can do, and try to find a similar program for different OSes. Even if you recursed the whole directory tree (hardly practical anyway), you would face problems such as being denied access to some files, and not accounting for the space wasted in each block at the end of files.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!