编写一个执行本地LINUX命令的程序。列出根目录下的内容。
package javaoperation;
import java.io.*;
public class List {
public static void main(String args[]) {
try {
Process p = Runtime.getRuntime().exec("ls /");
p.waitFor();
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = reader.readLine();
while (line != null) {
System.out.println(line);
line = reader.readLine();
}
} catch (IOException e1) {
} catch (InterruptedException e2) {
}
System.out.println("Done");
}
}