How to check whether an OutputStream is closed

后端 未结 7 1199
南笙
南笙 2020-12-10 10:29

Is there anyway to check whether an OutputStream is closed without attempting to write to it and catching the IOException?

For example, consider the fol

7条回答
  •  [愿得一人]
    2020-12-10 11:28

    The OutputStream itself does not support such a method. The Closable interface is defined in a way that once you call close() you are going to dispose of that OutputStream.

    Maybe you should revisit a bit the design of the application and check why you're not doing that and you're ending up with a closed OutputStream instance still running around in your application.

提交回复
热议问题