我有一个Main.java和Test.java类,我想编译并在Test.java代码中运行Main.java。这是我的代码:
Process pro1 = Runtime.getRuntime().exec("javac Main.java");
pro1.waitFor();
Process pro2 = Runtime.getRuntime().exec("java Main");
BufferedReader in = new BufferedReader(new InputStreamReader(pro2.getInputStream()));
String line = null;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
我在Main.java中只是打印了"ok",但是这段代码没有打印任何东西。问题出在哪里?
Process.getOutputStream
,不是吗? - Sasha Goldshtein