UPDATE: I found a crucial part to why this probably isn't working! I used System.setOut(out); where out is a special PrintStream to a JTextArea
这是代码,但我遇到的问题是,只有在我结束进程后才会打印出信息。
public Constructor() {
main();
}
private void main() {
btnStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
ProcessBuilder builder = new ProcessBuilder("java", textFieldMemory.getText(), "-jar", myJar);
Process process = builder.start();
InputStream inputStream = process.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream), 1);
String line;
while ((line = bufferedReader.readLine()) != null) {
System.out.println(line);
}
inputStream.close();
bufferedReader.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
});
}
电流输出:
Line 1
Line 2
Line 3
Line 4
Line 5
这是正确的输出,但是当我结束该过程时,它只会被打印为一个大块。
有谁知道问题是什么?如果是这样,你能帮我解释一下为什么会这样,提前谢谢你。