[英]Does InputStream.close() do anything?
As per the official documentation : 根据官方文件 :
public void close() throws IOException
public void close()抛出IOException
Closes this input stream and releases any system resources associated with the stream.
关闭此输入流并释放与该流关联的所有系统资源。
The close method of InputStream does nothing.
InputStream的close方法什么都不做。
So does it do nothing or something? 它什么都不做什么呢?
No it doesn't do anything, but InputStream
is an abstract
class where close
isn't abstract (it implements java.io.Closeable
), it has an empty body. 不,它什么都不做,但是
InputStream
是一个abstract
类,其中close
不是抽象的(它实现了java.io.Closeable
),它有一个空体。 Implementers of InputStream
can optionally override the method. InputStream
实现者可以选择覆盖该方法。 FileInputStream
closes the file input stream and releases any system resources where ByteInputStream
does nothing. FileInputStream
关闭文件输入流并释放ByteInputStream
什么也不做的任何系统资源。
The close()
method of InputStream
does nothing. InputStream
的close()
方法什么都不做。 The close()
method of subclasses of InputStream
may do something. InputStream
的子类的close()
方法可以做一些事情。
As @Kayaman says, InputStream
is an abstract class and close
method is not implemented there. 正如@Kayaman所说,
InputStream
是一个抽象类,并且没有在那里实现close
方法。 If your are curious you can see this link which sows you close method on java.io.FileInputStream
of openjdk version 8u40-b25, from GrepCode. 如果你很好奇,你可以在GrepCode上看到这个链接 ,它在openjdk版本8u40-b25的
java.io.FileInputStream
上播放你关闭的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.