本地文件的 java.io.InputStream 在关闭时什么时候会抛出异常?
大家下午好。我知道如果我们 close() 和 java.io.OutputStream,硬盘出现错误时可能会抛出IOException。
至于 java.io.InputStream, Javamex 声明:
<块引用>网络套接字的正常关闭实际上涉及通过连接发送关闭请求(TCP/IP FIN 数据包)并等待另一端确认此关闭请求。 (事实上,连接的另一端接着发送一个关闭请求,关闭端会确认该请求。)因此,在套接字输入流的情况下,关闭操作实际上涉及通过连接发送流量,因此关闭可以因错误而失败。
现在我想知道在什么情况下 java.本地文件的 io.InputStream (或子类)(不需要网络访问)曾经当我们调用 close() ?
Good afternoon all. I am aware that if we close() an java.io.OutputStream, it may throw an IOException when there are hard disk errors.
As for java.io.InputStream, Javamex states that:
A normal closure of a network socket actually involves a closure request (TCP/IP FIN packet) being sent over the connection and waiting for the other end to acknowledge this closure request. (In fact, the other end of the connection then in turn sends a closure request, which the closing end acknowledges.) So in the case of a socket input stream, a closure operation actually involves sending traffic over the connection and the closure can thus fail with an error.
Now I was wondering exactly under what circumstances will a java.io.InputStream (or sub class) for a local file (network access not needed) ever throw an exception when we call close() ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一种情况:
close()
函数时,可能会收到一个EBADF
错误,指示文件句柄无效。上述情况可能表明应用程序中其他地方存在严重错误。
Here's one situation:
close()
function, it may get anEBADF
error indicating that the file handle is invalid.The above situation probably indicates a serious bug somewhere else in the application.