本地文件的 java.io.InputStream 在关闭时什么时候会抛出异常?

发布于 2024-12-28 07:04:47 字数 1153 浏览 2 评论 0原文

大家下午好。我知道如果我们 close()java.io.OutputStream硬盘出现错误时可能会抛出IOException

至于 java.io.InputStreamJavamex 声明:

<块引用>

网络套接字的正常关闭实际上涉及通过连接发送关闭请求(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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

触ぅ动初心 2025-01-04 07:04:47

这是一种情况:

  • 应用程序的另一部分错误地关闭了与 InputStream 关​​联的底层文件描述符。当 Java 运行时调用系统 close() 函数时,可能会收到一个 EBADF 错误,指示文件句柄无效。

上述情况可能表明应用程序中其他地方存在严重错误。

Here's one situation:

  • Another part of the application has mistakenly closed the underlying file descriptor associated with the InputStream. When the Java runtime calls the system close() function, it may get an EBADF error indicating that the file handle is invalid.

The above situation probably indicates a serious bug somewhere else in the application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文