long freeSpaceUnix(String path,boolean kb,boolean posix,long timeout) throws IOException {
  if (path.length() == 0) {
    throw new IllegalArgumentException("Path must not be empty");
  }
  String flags="-";
  if (kb) {
    flags+="k";
  }
  if (posix) {
    flags+="P";
  }
  String[] cmdAttribs=flags.length() > 1 ? new String[]{DF,flags,path} : new String[]{DF,path};
  List<String> lines=performCommand(cmdAttribs,3,timeout);
  if (lines.size() < 2) {
    throw new IOException("Command line '" + DF + "' did not return info as expected "+ "for path '"+ path+ "'- response was "+ lines);
  }
  String line2=lines.get(1);
  StringTokenizer tok=new StringTokenizer(line2," ");
  if (tok.countTokens() < 4) {
    if (tok.countTokens() == 1 && lines.size() >= 3) {
      String line3=lines.get(2);
      tok=new StringTokenizer(line3," ");
    }
 else {
      throw new IOException("Command line '" + DF + "' did not return data as expected "+ "for path '"+ path+ "'- check path is valid");
    }
  }
 else {
    tok.nextToken();
  }
  tok.nextToken();
  tok.nextToken();
  String freeSpace=tok.nextToken();
  return parseBytes(freeSpace,path);
}

long freeSpaceUnix ( String path , boolean kb , boolean posix , long timeout ) throws IOException { if ( path . length ( ) == 0 ) { throw new IllegalArgumentException ( "Path must not be empty" ) ; } String flags = "-" ; if ( kb ) { flags += "k" ; } if ( posix ) { flags += "P" ; } String [ ] cmdAttribs = flags . length ( ) > 1 ? new String [ ] { DF , flags , path } : new String [ ] { DF , path } ; List < String > lines = performCommand ( cmdAttribs , 3 , timeout ) ; if ( lines . size ( ) < 2 ) { throw new IOException ( "Command line '" + DF + "' did not return info as expected " + "for path '" + path + "'- response was " + lines ) ; } String line2 = lines . get ( 1 ) ; StringTokenizer tok = new StringTokenizer ( line2 , " " ) ; if ( tok . countTokens ( ) < 4 ) { if ( tok . countTokens ( ) == 1 && lines . size ( ) >= 3 ) { String line3 = lines . get ( 2 ) ; tok = new StringTokenizer ( line3 , " " ) ; } else { throw new IOException ( "Command line '" + DF + "' did not return data as expected " + "for path '" + path + "'- check path is valid" ) ; } } else { tok . nextToken ( ) ; } tok . nextToken ( ) ; tok . nextToken ( ) ; String freeSpace = tok . nextToken ( ) ; return parseBytes ( freeSpace , path ) ; }
find free space on the * nix platform using the ' df ' command .
