Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用java逐行打印文本区域中的命令行输出?_Java_Swing_Cmd_Runtime_Jtextarea - Fatal编程技术网

如何使用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");