Have you ever seen a Java File close() throw an exception?

前端 未结 8 919
野性不改
野性不改 2020-12-31 00:10

Has anyone ever seen an exception thrown when calling close method on any closable object?

8条回答
  •  清歌不尽
    2020-12-31 00:43

    Not in terms of file-io, but in terms of sockets the close will raise IOException when the other side has aborted the connection. For example, when you fire a HTTP request on a (large) webpage and then immediately navigate away by clicking another link on the webpage (while it isn't finished loading), then the server side will get an IOException (or a subclass like ClientAbortException in Tomcat servers and clones) when the outputstream of the HTTP response is to be flushed/closed.

提交回复
热议问题