如果想要在控制台输出dos窗口的内容,可以使用如下方法实现:
代码如下:
public static void run() { try { Process process = Runtime.getRuntime().exec("ipconfig"); InputStream in = process.getInputStream(); BufferedReader br = new BufferedReader(new InputStreamReader(in)); //StringBuffer b = new StringBuffer(); String line=null; StringBuffer b=new StringBuffer(); while ((line=br.readLine())!=null) { b.append(line+"\n"); } System.out.println(b.toString()); process.waitFor(); } catch (Exception e) { e.printStackTrace(); }}