用java程序执行批处理文件并打印出控制台信息:
public class test {
public static void main(String[] args) {
try {
//执行批处理文件
Process process = Runtime.getRuntime().exec("C:\test\test.bat");
//打印控制台信息
BufferedReader read = new BufferedReader(new InputStreamReader(process.getInputStream()));
String str = null;
while ((str = read.readLine()) != null) {
System.out.println(str);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
上面程序的弊端是在DOS界面用javac和java编译执行是好使的,但是在eclipse中执行却不好使。