在流教程中,没有提到关闭从 Files.newInputStream(path)
获得的流。只有一些晦涩:
Whether the returned stream is asynchronously closeable and/or interruptible is highly file system provider specific and therefore not specified.
在这种情况下,什么是“异步”?如果我显式关闭流,或者另一个线程异步关闭流?
最佳答案
您绝对必须关闭获得的InputStream
,就像所有其他的一样。术语“可异步关闭”指的是在另一个线程因 I/O 操作而阻塞时关闭流的能力。
来自 InterruptibleChannel
文档:
A channel that implements this interface is asynchronously closeable: If a thread is blocked in an I/O operation on an interruptible channel then another thread may invoke the channel's close method. This will cause the blocked thread to receive an AsynchronousCloseException.
关于java - 我应该关闭使用 java.nio.file.Files.newInputStream 创建的 Streams 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28048325/