java中調用terminal,即Linux終端,執行相關命令
public static void main(String[] args) {
try {
Process p = Runtime.getRuntime().exec("md5sum /home/zcq/Desktop/ipv6"); //調用Linux的相關命令
InputStreamReader ir = new InputStreamReader(p.getInputStream());
LineNumberReader input = new LineNumberReader(ir); //創建IO管道,準備輸出命令執行後的顯示內容
String line;
while ((line = input.readLine()) != null) { //按行打印輸出內容
System.out.println(line);
}
} catch (
IOException e) {
e.printStackTrace();
}
}