如何使用java逐行打印文本区域中的命令行输出?
我有一个运行命令的代码,但它的输出没有同时进入文本区域如何使用java逐行打印文本区域中的命令行输出?,java,swing,cmd,runtime,jtextarea,Java,Swing,Cmd,Runtime,Jtextarea,我有一个运行命令的代码,但它的输出没有同时进入文本区域它在所有过程完成后显示输出 所以我需要在文本区域逐行打印输出 这是我的密码: try{ Process p = Runtime.getRuntime().exec(cmd,null,dir); BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
它在所有过程完成后显示输出
所以我需要在文本区域逐行打印输出 这是我的密码:
try{
Process p = Runtime.getRuntime().exec(cmd,null,dir);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
// read the output from the command
while ((k = stdInput.readLine()) != null) {
//result= result +"\n"+k+"\n";
edlflashTextArea.append(k);
System.out.println(k);
}
// read any errors from the attempted command
while ((k = stdError.readLine()) != null) {
//result= result+"\n"+k+"\n";
edlflashTextArea.append(k);
}
edlflashTextArea.append("DONE");
} catch (IOException l) {
System.out.println("exception happened - here's what I know: ");
StringWriter sw= new StringWriter();
l.printStackTrace(new PrintWriter(sw));
String ExceptionAsString=sw.toString();
System.out.println(ExceptionAsString);
edlflashTextArea.append(ExceptionAsString);
}
只需在行尾追加一个新行(“\n”
)字符:
edlflashTextArea.append("\n");
只需在行尾追加一个新行(“\n”
)字符:
edlflashTextArea.append("\n");