Java Utililty Methods Disk Free Space Get

List of utility methods to do Disk Free Space Get

Description

The list of methods to do Disk Free Space Get are organized into topic(s).

Method

longgetFreeSpace(File directory)
get Free Space
return directory.getUsableSpace() / KILOBYTE;
longgetFreeSpace(File file)
get Free Space
long free = file.getFreeSpace();
while (free == 0) {
    file = file.getParentFile();
return free;
longgetFreeSpace(String dir)
Returns the free disk space on the partition storing the given directory.
return new File(dir).getFreeSpace();
longgetFreeSpace(String pathname)
get Free Space
return (new File(pathname)).getUsableSpace();
longgetFreeSpaceOnPartition(File f)
Returns the free space on the partion where the specified file is located
return f.getUsableSpace();
longgetTreeSize(File root)
get Tree Size
long size = 0;
File files[] = root.listFiles();
if (files == null)
    return size;
for (File file : files) {
    if (file.isDirectory())
        size += getTreeSize(file);
    else
...
longgetTreeSize(File root)
Get the size of a file or a directory tree
long size = 0;
if (root.isFile())
    size = root.length();
else {
    for (File f : root.listFiles()) {
        size += getTreeSize(f);
return size;
longgetUnixFreeSpace(String pathname)
get Unix Free Space
try {
    String[] command = { "df", "-Pk", pathname };
    Process process = Runtime.getRuntime().exec(command);
    InputStream procOutput = process.getInputStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(procOutput));
    reader.readLine();
    String line = reader.readLine();
    String[] fields = line.split("\\s+");
...