我正在尝试读取我为界面创建的一个actionPerformed
函数的函数中的输入流。为此,我实现了一个可运行的类。问题是我得到了一个量子输出流,这意味着,可以说我得到了50行,而不是一个大的停顿,还有50行等等。更大的问题是线的顺序不一致。这里是我的代码看起来像...Java,在jButton中执行读取输入流操作执行
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)
{
try{
String sCommand = "cmd /c \"myenvsetup.bat && myprogram.exe\"";
Runtime rt = Runtime.getRuntime();
pr = rt.exec(sCommand);
java.awt.EventQueue.invokeLater(new Runnable()
{
public void run()
{
try{
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line = null;
while((line = input.readLine()) != null){
jTextArea1.append(line + "\n");
jTextArea1.scrollRectToVisible(new Rectangle(0, jTextArea1.getHeight(), 0, 0));
jTextArea1.update(jTextArea1.getGraphics());
}
pr.waitFor();
} catch (Exception e) {
}
}
});
} catch (Exception e){
}
}
对于[示例](http://stackoverflow.com/questions/30797851/update-jlabel-content-from-the-output-of-shell-script/30798684#30798684),[示例](http:///stackoverflow.com/questions/34858405/how-can-i-make-this-method-update-the-gui-within-my-loop/34864911#34864911),[示例](http://stackoverflow.com/问题/ 15801069 /印刷-A-java的InputStream的从 - 一个过程/ 15801490#15801490)。可能的原因是对'update'的调用,你应该不必这么做 – MadProgrammer