*
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 Android Security Essentials Live Lessons this week in the Android 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: 173

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: 8843
    
    7

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: 19655
    
  18

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: 19655
    
  18

You're welcome.
 
Don't get me started about those stupid light bulbs.
 
subject: can i use java to check the disk usage?
 
Similar Threads
Memory usage of java application with tomcat
Java memory usage
Reclaiming Disk space in Vista
Formatting problem
Chunk Size