System.out closed? Can I reopen it?

前端 未结 7 2409
逝去的感伤
逝去的感伤 2020-12-06 09:34

I was helping a friend to write some Java code, who doesn\'t know a lot about Java. So I wrote him some helper functions to easily get things done that are a little quirky i

7条回答
  •  日久生厌
    2020-12-06 10:09

    If you want to try the output on JVM console, you'd better to get a Console instance with System.console(). And then get the PrintWriter with console.writer() method. After using the PrintWriter, you can close it. Based on the console description of JavaDoc,

    Invoking close() on the objects returned by the reader() and the writer() will not close the underlying stream of those objects.

    You can do this again and again. No need to worrying about reopen the stream.

提交回复
热议问题