• Post Reply Bookmark Topic Watch Topic
  • New Topic

how to get disk space usage Programmatically  RSS feed

 
Amit Goel
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I require to find out programmatically that how much space is free on my hard disk. can anyone plz tell me how can i do it.?
Please reply ASAP.
amit
 
C. Nimo
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I am not sure you're going to like this one..
AFAIK - you can't do it directly in Java, and this is platform independant.
If I am not mistaken, you will have to run an OS command that returns the free space on your disk, and parse the output.
you can do that via Runtime.exec().
Another option - if you need to know that you have Xmb free - is try and allocate a file of this size and watch it fail or succeed...
Nimo.
 
Amit Goel
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reply,
but I know that Runtime.exec() will do that job for me as i can provide the paramter to exec as "xterm....." but the only thing required is what exactly this parameter be so that i can run the 'df' command and capture the output of command in a txt file.
amit
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm moving this to the Java In General (Intermediate) Forum seeins as though this isn't a topic on the Programmer's Certification Exam.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may execute the command:

Hope this help.
Nick
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!