在社区看到java调用本地dos命令的代码,特贴出来

String command = "ipconfig"; 
Runtime run = Runtime.getRuntime(); 
Process pro = run.exec(command); 
BufferedReader read = new BufferedReader(new InputStreamReader(pro.getInputStream(), "GBK")); 
StringBuilder sb = new StringBuilder(); 
String con = ""; 
while(null != (con = read.readLine())) { 
sb.append(con + "\r\n"); 
} 
System.out.println(sb.toString()); 
执行其他命令,就把command修改了就行,不知道是不是你想要的。

posted on 2016-03-27 12:57  WesTward  阅读(437)  评论(0编辑  收藏  举报