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

前端 未结 8 867
野性不改
野性不改 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:40

    Yes, it's not that rare, IMHO if you are working with anything other than non-local disk files.

    Close() works if at that point your closable is still valid and open. Many things like pipes, remote files, etc., can die prematurely.

    In addition, I have seen code that ignores errors on open and write and still tries to close (e.g., in a finally block).

提交回复
热议问题