• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

can i use java to check the disk usage?

 
rosy Jovita
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

is it possible to collect information about the disk usage.
for example: total space for local c:\, total used and total free.
can i do this in pure java?Thanks for any replies.
 
Carey Brown
Bartender
Pie
Posts: 1635
22
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's 3 source files that I pulled out of one of my projects which should get you started (hope I got them all, if not, let me know).







 
Joe Ess
Bartender
Posts: 9312
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or you could use the methods of java.io.File like getFreeSpace() and getTotalSpace().
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Ess wrote:Or you could use the methods of java.io.File like getFreeSpace() and getTotalSpace().

+1. These got added in Java 6. Note that they are not static methods, because the values (may) differ for each root. Simply create a new file for C:\:
You can also use File.listRoots() to list all roots, then call these methods on those.
 
rosy Jovita
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carey,

thanks, it works.

and joe, thanks for the suggestion.

and Rob, that was very helpful

Thanks guys.
 
Rob Spoor
Sheriff
Pie
Posts: 20610
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic