Writing to console and text file

后端 未结 3 1320
闹比i
闹比i 2020-11-29 08:44

I found the code below from the internet, works but it doesn\'t write the printed console to omt.txt, it only writes the System.out.println statements after the

3条回答
  •  青春惊慌失措
    2020-11-29 09:11

    In System.java, this is the declaration of the out property:

    public final static PrintStream out
    

    You'll see that it can only be one PrintSteam object at a time. So it's either the console or the file, but not both.

    At this line, you have effectively re-channelled the destination:

    System.setOut(ps);
    

    So your output stops displaying on the console.

提交回复
热议问题