如何在java程序中 執行linux命令或者執行shell腳本呢 ,java專門提供了一個進程類專門解決該問題
代碼:
public static void main(String[] args) throws IOException, InterruptedException { //正常寫 linux命令即可 、比如:mkdir xx/touch b.txt/sh start.sh/sh stop.sh String commend = "sh start.sh"; //程序執行,核心代碼 Process process = Runtime.getRuntime().exec(commend); //等待執行結果,0表示執行成功 int i = process.waitFor(); }