How to check whether an OutputStream is closed

后端 未结 7 1232
南笙
南笙 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:04

    No. If you implement your own, you could write an isClosed method, but if you don't know the concrete class, then no. OutputStream is just an abstract class. Here's it's implementation:

       /**
     * Closes this output stream and releases any system resources 
     * associated with this stream. The general contract of close 
     * is that it closes the output stream. A closed stream cannot perform 
     * output operations and cannot be reopened.
     * 

    * The close method of OutputStream does nothing. * * @exception IOException if an I/O error occurs. */ public void close() throws IOException { }

提交回复
热议问题