
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();
}
这篇博客主要介绍了如何使用Java的Runtime类执行.bat批处理文件。通过Runtime.getRuntime().exec()方法创建进程,然后读取并打印.bat文件的输出内容。在执行过程中,需要注意异常处理,确保资源得到正确关闭。
784

被折叠的 条评论
为什么被折叠?



