How to redirect console content to a textArea in Java?

前端 未结 5 593
天涯浪人
天涯浪人 2020-12-05 15:18

I\'m trying to get the content of console in a textArea in java.

For example if we have this code,

class FirstApp {
    public static void main (Stri         


        
5条回答
  •  南笙
    南笙 (楼主)
    2020-12-05 15:54

    One of the way you can do it by setting the System OutputStream to a PipedOutputStream and connect that to a PipedInputStream that you read from to add text to your component, E.g

    PipedOutputStream pOut = new PipedOutputStream();   
    System.setOut(new PrintStream(pOut));   
    PipedInputStream pIn = new PipedInputStream(pOut);  
    BufferedReader reader = new BufferedReader(new InputStreamReader(pIn));
    

    Have u looked at the following link ? If not, then you must.

    • Print to textArea instead of console in eclipse ?
    • Redirecting all console o/p to GUI textbox
    • Simple java console - Swing based

提交回复
热议问题