I recently found out that you can close PrintStream System.out!
So the code snippet:
System.out.println("foo");
System.out.close();
System.out.println("bar");
will produce the result:
foo
instead:
foo
bar
Now to my question:
Is there a way to restore PrintStream after closing it?
I saw a method setOut(PrintStream p)in there Systemthat allows me to set the System.out thread to some other thread. But I do not know how to create a stream that prints to the console!
Once again, my question is NOT if I can open System.outprintstream again ! I ask if it is possible to reproduce the steps that java takes inside to open PrintStream, which prints to the console AFTER closing System.outPrintStream!
source
share