aspose file tools*
The moose likes I/O and Streams and the fly likes can i use java to check the disk usage? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "can i use java to check the disk usage?" Watch "can i use java to check the disk usage?" New topic
Author

can i use java to check the disk usage?

rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
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
Ranch Hand

Joined: Nov 19, 2001
Posts: 209

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).









Sent from my IBM 360 mainframe
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8971
    
    9

Or you could use the methods of java.io.File like getFreeSpace() and getTotalSpace().


[How To Ask Questions On JavaRanch]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
rosy Jovita
Ranch Hand

Joined: Jan 05, 2010
Posts: 45
Hi Carey,

thanks, it works.

and joe, thanks for the suggestion.

and Rob, that was very helpful

Thanks guys.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19762
    
  20

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can i use java to check the disk usage?