您的位置 首页 java

Java执行电脑cmd命令

直接上代码

 // write your code here
// String[] command = new String[]{"ipconfig", "/all"};
String [] command=new String[]{"ping","www.baidu.com"};
Process process = Runtime.getRuntime().exec(command);

 InputStream  is = process.getInputStream();
InputStreamReader inputStreamReader = new InputStreamReader(is, Charset.forName("GBK"));
BufferedReader reader = new BufferedReader(inputStreamReader);
for (String line = null; (line = reader.readLine()) != null; ) {
    System.out.println(line);
}
reader.close();  

效果

文章来源:智云一二三科技

文章标题:Java执行电脑cmd命令

文章地址:https://www.zhihuclub.com/187532.shtml

关于作者: 智云科技

热门文章

网站地图