System.out.println not working after printWriter on System.out

后端 未结 1 854
挽巷
挽巷 2021-01-27 06:11

I am facing a rather unusual situation. I am using printWriter with System.out to print the bytes from a file onto console, first using a ByteStr

相关标签:
1条回答
  • 2021-01-27 06:16

    I can see 2 significant problems with your FileStream and CharacterStream classes.

    • Both classes call close() on the PrintWriter that wraps System.out. When that happens System.out will be closed, and no further writes to it will be permitted.

    • Both classes squash IO exceptions. That is they catch the exception, say nothing, and continue as if nothing happened. That is extremely poor coding practice ... and it is most likely hiding the exceptions that happen when you write to the closed System.out stream.

    There are also a variety of style problems, the worst of which is your poor choice of method and class names. For example the printOnConsole methods don't print on the console. Rather they print on the standard output stream ... which may go to somewhere other than the console. (And your application can't tell!!)

    0 讨论(0)
提交回复
热议问题