版权声明:本文为博主原创文章,未经博主允许不得转载。更好的样式阅读体验可点击文章底部<<查看原文>> https://blog.csdn.net/huuinn/article/details/79320722
java调用系统命令范例
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
public class SystemCommandCall {
public static void main(String[] args) throws Exception {
String cmd = "ping 8.8.8.8"; //运行的命令
Runtime runtime = Runtime.getRuntime();
Process p = runtime.exec(cmd);
InputStream is = p.getInputStream();
InputStreamReader isr = new InputStreamReader(is, "UTF-8");
BufferedReader reader = new BufferedReader(isr);
for (String line; (line = reader.readLine()) != null;) {
System.out.println(line);
}
}
}
查看原文: https://www.huuinn.com/archives/566
更多技术干货: 风匀坊
关注公众号:风匀坊