Here you can find the source of getUnixFreeSpace(String pathname)
public static long getUnixFreeSpace(String pathname) throws IOException
//package com.java2s; // BSD License (http://www.galagosearch.org/license) import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public class Main { public static long getUnixFreeSpace(String pathname) throws IOException { try {//from w w w . j ava 2 s. c o m // BUGBUG: will not work on windows String[] command = { "df", "-Pk", pathname }; Process process = Runtime.getRuntime().exec(command); InputStream procOutput = process.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(procOutput)); // skip the first line reader.readLine(); String line = reader.readLine(); String[] fields = line.split("\\s+"); reader.close(); process.getErrorStream().close(); process.getInputStream().close(); process.getOutputStream().close(); process.waitFor(); long freeSpace = Long.parseLong(fields[3]) * 1024; return freeSpace; } catch (InterruptedException ex) { return 0; } } }