How to redirect console content to a textArea in Java?

前端 未结 5 582
天涯浪人
天涯浪人 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 16:04

    You'll have to redirect System.out to a custom, observable subclass of PrintStream, so that each char or line added to that stream can update the content of the textArea (I guess, this is an AWT or Swing component)

    The PrintStream instance could be created with a ByteArrayOutputStream, which would collect the output of the redirected System.out

提交回复
热议问题