wood burning stoves 2.0*
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


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 170

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

Joined: Oct 29, 2001
Posts: 8713
    
    6

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


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19552
    
  16

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: 19552
    
  16

You're welcome.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: can i use java to check the disk usage?
 
Similar Threads
Reclaiming Disk space in Vista
Chunk Size
Java memory usage
Formatting problem
Memory usage of java application with tomcat