实例:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Lin {
public static void main(String[] args) {
Process process =null;
//chmod 777 有时需要给文件权限
//备注 在Android上执行可能需要su权限
String command1 = "md5sum "+ " /root/lin";//命令加路径
try {
process = Runtime.getRuntime().exec(command1);//执行命令
InputStreamReader ips = new InputStreamReader(process.getInputStream());
BufferedReader br = new BufferedReader(ips);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}