java执行exe,bat 文件的方法_Android, Python及开发编程讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  Android, Python及开发编程讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 1907 | 回复: 0   主题: java执行exe,bat 文件的方法        下一篇 
    本主题由 koei123 于 2015-7-14 11:05:47 移动
曹先丰
注册用户
等级:中士
经验:208
发帖:72
精华:0
注册:2012-1-9
状态:离线
发送短消息息给曹先丰 加好友    发送短消息息给曹先丰 发消息
发表于: IP:您无权察看 2015-7-10 14:48:31 | [全部帖] [楼主帖] 楼主

======================exe=======================
try {
      Process proc = Runtime.getRuntime().exec(YourCommand);//你的exe文件名   
      BufferedReader in = new BufferedReader(
      new InputStreamReader(proc.getInputStream()));
      String text = null;
      while((text = in.readLine()) != null) {
            System.out.println(text);
      }
}
catch(IOException ioError) {
      ioError.printStackTrace();
      System.exit(0);
}
}
}
======================bat=======================
try{
      String exeBat ="c:/test.bat";
      Process child = Runtime.getRuntime().exec(exeBat);
      InputStream in = child.getInputStream();
      BufferedReader br=new BufferedReader(new InputStreamReader(in));
      String line = br.readLine().toString();
      while(line!=null ){
            System.out.println(line); //输出测试
            line = br.readLine().toString();
      }
      try{
            child.waitFor();
            br.close();
            in.close();
      }catch (Exception e) {
      e.printStackTrace();
}
}catch (Exception e) {
      e.printStackTrace();
}


--转自 北京联动北方科技有限公司



该贴由koei123转至本版2015-7-14 11:05:47



赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论