利用java执行dos命令,可以利用java.lang包下的Runtime和Process类,完成对dos命令的执行,代码如下:
Example
package dos;
import java.io.*;
public class testdos
{
public static void main(String[] args) throws IOException {
String command = "ipconfig";
Runtime r = Runtime.getRuntime();
Process p = r.exec(command);
//System.out.println(p.getClass().getName());
BufferedReader br = new BufferedReader(new InputStreamReader(
p.getInputStream()));
StringBuffer sb = new StringBuffer();
String inline;
while (null != (inline = br.readLine())) {
sb.append(inline).append("\n");
}
System.out.println(sb.toString());
}
}
写的真牛比
不赖,简单正确