Update:
, FileSystemUtils, .
dos fsutil:
fsutil volume diskfree [drive letter]
:
Total
Total
Total
Unix - "df -k", "1024 " "Free" ( ). , 1024.
Filesystem 1024-blocks Free %Used Iused %Iused Mounted on
/dev/hd4 32768 16016 52% 2271 14% /
/dev/hd2 4587520 1889420 59% 37791 4% /usr
/dev/hd9var 65536 12032 82% 518 4% /var
/dev/hd3 819200 637832 23% 1829 1% /tmp
/dev/hd1 524288 395848 25% 421 1% /home
/proc - - - - - /proc
/dev/hd10opt 65536 26004 61% 654 4% /opt
, FileSystemUtils "totalSpaceKB()", , . Windows - ( "", fsutil, ):
long totalSpaceWindows(String path) throws IOException {
path = FilenameUtils.normalize(path);
if (path.length() > 2 && path.charAt(1) == ':') {
path = path.substring(0, 2);
}
String[] cmdAttribs = new String[] {
"cmd.exe",
"/C",
"fsutil volume diskfree " + path
+ " | Find \"Total # of bytes\"" };
List lines = performCommand(cmdAttribs, Integer.MAX_VALUE);
if (lines.size() > 0) {
String line = (String) lines.get(0);
String bytes = line.split(":")[1].trim();
return Long.parseLong(bytes);
}
throw new IOException(
"Command line 'fsutil volume diskfree' did not return
+ "any info for path '" + path + "'");
}
Unix , freeSpaceUnix(), tok.nextToken()
tok.nextToken();
tok.nextToken();
String freeSpace = tok.nextToken();
return parseBytes(freeSpace, path);
}
.
, , .
( , ).
Java 6 (. bug). , , .
Apache commons-io FileSystemUtils, freeSpaceKb(). Windows Unix (. Javadoc )
Javadoc:
public static long freeSpaceKb (String path) IOException
, . FileSystemUtils.freeSpaceKb( "C:" );//Windows FileSystemUtils.freeSpaceKb( "/" );//* nix
. "dir/-c" Windows, "df -kP" AIX/HP-UX "df -k" Unix. , Windows Unix df, GNU -k ( -kP). , , , , . , , JIRA-, df -k , .