Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to know Remaining Disk Space with JDK 1.5  RSS feed

 
James Basller
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a trouble that how can I find available disk space with JDK 1.5? I think in JDK 1.6 it's provided by IO API. But I have to use JDK1.5. is there any way to find out these things?

Thanks
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm reading about jakarta commons IO FileSystemUtils class.

It has the method freeSpaceKb:


public static long freeSpaceKb(String path)
throws IOException

Returns the free space on a drive or volume in kilobytes by invoking the command line.

FileSystemUtils.freeSpaceKb("C:"); // Windows
FileSystemUtils.freeSpaceKb("/volume"); // *nix

The free space is calculated via the command line. It uses 'dir /-c' on Windows, 'df -kP' on AIX/HP-UX and 'df -k' on other Unix.

In order to work, you must be running Windows, or have a implementation of Unix df that supports GNU format when passed -k (or -kP).

(from http://commons.apache.org/io/api-release/index.html?org/apache/commons/io/FileSystemUtils.html )

ALSO:

SIGAR ( http://support.hyperic.com/display/SIGAR/Home )
System Information Gatherer And Reporter

looks full of features for querying system resources, but I've never used it.
 
Tim McGuire
Ranch Hand
Posts: 820
IntelliJ IDE Tomcat Server VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just testing out SIGAR and found it very easy to install and use. For example, here is how you would use it to get remaining disk space:



it was as easy as downloading a package and adding it to the classpath. The resources it reported are the same as what my system reported.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!