Re: BufferedInputStream -- does not recommend "close()"?
- From: "Adam Maass" <adam.nospam.maass@xxxxxxxxxxx>
- Date: Sun, 6 Jan 2008 20:25:19 -0800
"Stefan Ram" <ram@xxxxxxxxxxxxxxxxxx> wrote in message news:BufferedInputStream-20080107041811@xxxxxxxxxxxxxxxxxxxxxxxxxx
The operation »close()« is mentioned in the class documentation
But nowhere does it recommend to use »close()«.
I had expected the constructor documentation to
say something like
»Whenever an object of this class has been constructed
successfully it needs to be closed at some instant in the
future to avoid resource leaks, because only by closing
all resource allocated by the construction will be
But this is not so.
The tutorial also does not recommend close:
I used to believe that closing was important.
Why is it not recommended in the documentation nor the tutorial?
(When insisting on the use of »close()«, I'd
like to have some evidence for its necessity.)
Huh. I am slightly mystified as well.
But I believe a plausible explanation might be that BufferedInputStream itself doesn't hold any system resources; it simply forwards the "close" call onto the InputStream it wraps. It is those wrapped objects whose "close" methods must be called. So since for the BufferedInputStream itself, the "close" call isn't so critical, maybe (just maybe) Sun decided not to insert a stern warning into the documentation of that class.
It is best practice to close all streams (and readers/writers) when you are done with them. Nasty unpredictible things can happen otherwise.
-- Adam Maass
- Prev by Date: Re: How to search in a file efficiently (=fast !) for a certain hex value ?
- Next by Date: Re: Why does compiler only look at public methods of superclasses of...?
- Previous by thread: Questions about buffered streams
- Next by thread: Re: BufferedInputStream -- does not recommend "close()"?