As per the official documentation:
public void close() throws IOException
Closes this input stream and releases any system resources associated with the stream.
The close method of InputStream does nothing.
So does it do nothing or something?
The operating system will only allow a single process to open a certain number of files, and if you don't close your input streams, it might forbid the JVM from opening any more. I am talking about an InputStream in general. And not just a FileInputStream.
It's important to close any resource that you use. in. close will close BufferedReader, which in turn closes the resources that it itself uses ie. the InputStreamReader.
Closing an InputStreamReader will also close the InputStream instance from which the InputStreamReader is reading.
copy(InputStream, OutputStream) must not close the OutputStream . You can use it for example to concatenate different InputStreams and in this case it would be a bad idea if it would close the provided Input- and/or OutputStream. As a rule of thumb any method should close only those steams it opens.
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. Implementers of InputStream
can optionally override the method. FileInputStream
closes the file input stream and releases any system resources where ByteInputStream
does nothing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With