gpt4 book ai didi

java - 本地文件的 java.io.InputStream 何时会在关闭时抛出异常?

转载 作者:行者123 更新时间:2023-11-30 09:41:34 24 4
gpt4 key购买 nike

大家下午好。我知道如果我们 close()一个java.io.OutputStream , it may throw an IOException当有硬盘错误时。

至于java.io.InputStream , Javamex指出:

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.

现在我想知道在什么情况下 java.io.InputStream 会(或子类)本地文件(网络访问不需要)曾经在我们调用close()时抛出异常?

最佳答案

这是一种情况:

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

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

关于java - 本地文件的 java.io.InputStream 何时会在关闭时抛出异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8965266/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com