Java中Runtime指定运行目录
来源:互联网 发布:php评论盖楼 编辑:程序博客网 时间:2024/05/18 03:35
1、查了一下网上通用的方法,
public static boolean runtimeExec(String cmd, File path) {Process proc;try {Runtime rt = Runtime.getRuntime();proc = rt.exec(cmd, null, path);InputStream stderr = proc.getErrorStream();InputStreamReader isr = new InputStreamReader(stderr);BufferedReader br = new BufferedReader(isr);String line = null;while ((line = br.readLine()) != null) {System.out.println(line);}int exitVal = proc.waitFor();return exitVal == 0;} catch (Exception e) {e.printStackTrace();return false;}}
不过试了一下,这个还是会提示文件找不到。放弃。
2、
public static boolean runtimeExec(String cmd, File path) {Process proc;try {StringBuilder builder=new StringBuilder();builder.append("cmd /c ");builder.append(path);builder.append(File.separator);builder.append(cmd);Runtime rt = Runtime.getRuntime();proc = rt.exec(builder.toString());InputStream stderr = proc.getErrorStream();InputStreamReader isr = new InputStreamReader(stderr);BufferedReader br = new BufferedReader(isr);String line = null;while ((line = br.readLine()) != null) {System.out.println(line);}int exitVal = proc.waitFor();return exitVal == 0;} catch (Exception e) {e.printStackTrace();return false;}}Sucess!!
0 0
- Java中Runtime指定运行目录
- Java代码在指定目录下运行DOS命令
- Java中使用Runtime和Process类运行外部程序
- Java中使用Runtime和Process类运行外部程序
- Java中使用Runtime和Process类运行外部程序
- Java中使用Runtime和Process类运行外部程序
- Java中使用Runtime和Process类运行外部程序
- Java中使用Runtime和Process类运行外部程序
- Java中使用Runtime和Process类运行外部程序
- Java中使用Runtime和Process类运行外部程序
- Java中使用Runtime和Process类运行外部程序
- Java中使用Runtime和Process类运行外部程序
- Java中使用Runtime和Process类运行外部程序
- Java中使用Runtime和Process类运行外部程序
- Java中Runtime运行时环境机制总结
- java 输出指定目录
- java 运行指定classpath
- Java中遍历出指定目录中的所有文件
- Yii2实现手机二维码扫一扫登入
- 程序员进阶之路—如何独当一面
- 基于Java语言的安卓编程学习之六Activity的切换
- 搭建Android开发平台(Android studio)
- awt--常用组件的使用
- Java中Runtime指定运行目录
- UIView 添加category方法 得到view的单个frame值
- 如何扩展或者添加硬盘给VMware的Linux操作系统
- 实用小控件-自定义View-矩形(正方形)
- jzoj 3885 搞笑的代码
- libjson-rpc-cpp windows使用探索
- WebStorm+Chrom 调试React Native 项目图文详解
- 组合全排列算法
- Python学习笔记:python3中的range()函数的返回对象类型