java.util.zip.ZipFile.close() 什么时候抛出 IOException?
在什么情况下会 java.util.zip.ZipFile.close() 抛出 IOException?它的方法签名表明它可以被抛出,但从源代码来看,似乎没有任何地方可能发生这种情况,除非它是在本机代码中。在捕获异常时可以采取什么纠正措施(如果有)?
Under what circumstances would java.util.zip.ZipFile.close() throw an IOException? Its method signature indicates that it can be thrown, but from the source code there doesn't seem to be any place where this could happen, unless it's in native code. What corrective action, if any, could be taken at the point where that exception is caught?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
来自 API 文档
ZipFile.close()
:和
InputStream.close()
抛出IOException
,因此ZipFile.close()
也必须抛出它。根据 API 文档InputStream.close()
,它会抛出一个IOException
“如果发生 I/O 错误”。这不是很具有描述性,但它正在撒一张广泛的网。 InputStreams 可以表示来自文件系统、网络、内存等的流。InputStreams 可以涉及需要刷新的缓冲区、需要关闭的套接字、需要释放的资源、需要释放的锁等。IOExceptions 可以发生的原因有多种。From the API docs on
ZipFile.close()
:And
InputStream.close()
throws anIOException
, soZipFile.close()
has to throw it too. According to the API docs forInputStream.close()
, it throws anIOException
"if an I/O error occurs". That's not very descriptive but it's casting a wide net. InputStreams can represent streams coming from the filesystem, network, memory, etc. InputStreams can involve buffers that need to be flushed, sockets that need to be closed, resources that need to be freed, locks that need to be freed, etc. IOExceptions can happen for a variety of reasons.从人关闭(2):
From man close(2):
我不确定,但我认为当发生以下事件之一时会引发 IOException:
可能有更多的事件是原因,但这是我现在能想到的唯一两个。
I'm not sure but I think IOException is thrown when one of the following events happen:
A lot more events might be the reason but those are the only two I could think of right now.
ZipFile.close()
的文档说:据推测,本机
close
方法正在执行关闭 InputStreams 的操作。InputStream
的close
方法将IOException
作为已检查异常。最可能的原因是底层文件系统中
写入 zip 文件的文件系统空间不足错误。除非您能够找出原因并立即解决它,否则您所能做的就是向用户报告情况。The documentation for
ZipFile.close()
says:Presumably the native
close
method is performing the close the InputStreams.The
close
method ofInputStream
hasIOException
as a checked exception.The most likely cause is an
out of space condition on the filesystem where the zip file is being writtenerror in the underlying filesystem. Unless you can identify the cause and work around it on the fly, all you can do is report the condition to the user.