标签:class blog code java com get
package com.wzw.util; import java.io.BufferedReader; import java.io.InputStreamReader; public class CmdDemo { public static void main(String[] args) { BufferedReader br = null; try { Process p = Runtime.getRuntime().exec("net user"); br = new BufferedReader(new InputStreamReader(p.getInputStream())); String line = null; while ((line = br.readLine()) != null) { System.out.println(line); } } catch (Exception e) { e.printStackTrace(); } finally { if (br != null) { try { br.close(); } catch (Exception e) { e.printStackTrace(); } } } } }
执行结果:
\\PC-20140327DFCW 的用户帐户 ------------------------------------------------------------------------------- Administrator Guest 命令成功完成。
JAVA中调用CMD命令,并输出执行结果,布布扣,bubuko.com
标签:class blog code java com get
原文地址:http://blog.csdn.net/ibey0nd/article/details/31403457