Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to find the available disk space  RSS feed

 
srinivas daroori
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking at finding out a way to find out the available disk space on the hard drive from my java program. Is there any method to do the same?
Thanks!
 
Billybob Marshall
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not without JNI native coding down to the particular OS running on. Regardless though, your app shouldn't need to know this. If you're trying to determine if there's "enough" space before doing something, instead just assume there is enough, and fail as gracefully as you can if you get an I/O error.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I suppose one way is to write a bunch of files until you get an I/O error, then delete the files afterwards. The nymber of bytes you wrote before the I/O error is probably the available disk space.
 
srinivas daroori
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really wondering to see that there is no STRAIGHT FORWARD way to find out the available disk space on the machine from java program. It is very much needed in many places.
 
Adrian Yan
Ranch Hand
Posts: 688
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Available disk space is based on O/S design and api. Java doesn't do that very well.
On linux, I suppose you can do a df and interpret the result.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!