I am attempting to execute a unix "df -k" command in java. I have the following example.. My question is how do I parse the results of the command in order to grab the available bytes versus just printing it out????

import java.io.*;

public class unixcmd
{
public static void main(String args[])
{
try
{
Process p=Runtime.getRuntime().exec("df -k");
p.waitFor();
BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
while(line!=null)
{
System.out.println(line);
line=reader.readLine();
how do I grab this information and put it into an array??
}

}
catch(IOException e1) {}
catch(InterruptedException e2) {}

System.out.println("Done");
}
}

You can use String.split() with an appropriate expression to turn that into a String[] array.

Thank you. I was wondering that, but not sure if the df returned as tab delimited... so I am assuming it is??

Give it a quick try. It looks like it to me, but I can't test that here.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.