java.util.zip.ZipFile.close()什么时候抛出IOException? [英] when does java.util.zip.ZipFile.close() throw IOException?

查看:804
本文介绍了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?

推荐答案

来自 上的API文档ZipFile。 close()


关闭此ZIP文件将关闭之前返回的所有输入流通过调用 getInputStream 方法。

InputStream.close() 抛出 IOException ,所以 ZipFile.close() 也必须抛出它。根据 InputStream.close() ,如果发生I / O错误,它会抛出 IOException 。这不是很具描述性,但它正在广泛展示。 InputStreams可以表示来自文件系统,网络,内存等的流.InputStreams可能涉及需要刷新的缓冲区,需要关闭的套接字,需要释放的资源,需要释放的锁等等.IOExceptions可以发生的原因有很多。

And InputStream.close() throws an IOException, so ZipFile.close() has to throw it too. According to the API docs for InputStream.close(), it throws an IOException "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.

这篇关于java.util.zip.ZipFile.close()什么时候抛出IOException?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆