设为首页 加入收藏

TOP

Java调用Windows控制台命令
2014-11-12 11:30:10 来源: 作者: 【 】 浏览:29
Tags:Java 调用 Windows 控制台 命令

  方法一:


  public static void main(String[] args)


  {


  InputStream ins = null;


  String[] cmd = new String[]{ "cmd.exe", "/C", "ipconfig" };


  try


  {


  Process process = Runtime.getRuntime().exec(cmd);


  // cmd 的信息


  ins = process.getInputStream();


  BufferedReader reader = new BufferedReader(new InputStreamReader(


  ins));


  String line = null;


  while ((line = reader.readLine()) != null)


  {


  // 输出


  System.out.println(line);


  }


  int exitValue = process.waitFor();


  System.out.println("返回值:" + exitValue);


  // 关闭


  process.getOutputStream().close();


  }


  catch (Exception e)


  {


  e.printStackTrace();


  }


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇我的第一个JavaMidlet 下一篇DWRUtil的方法使用说明

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: