This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
As you can notice i have created BufferedReader object in using inStream object which is being passed to load method.I am closing the inStream object in finally block of methodA but i am not closing the in object created in method load.
Now my question is does the in object gets closed automatically when inStream object is closed as it was created through instrean object?
[ Added code tags - Jim ] [ January 12, 2007: Message edited by: Jim Yingst ]
Hi i was doing some of my own search on this problem when i realized that in object is of type BufferedReader.
Correct me if i am wrong! A buffred reader will use the input stream passed to it(as instream in the example) for reading and wont create a new stream of its own. so do i really need to call close() method on in object?
author and iconoclast
Technically, no; it won't hurt anything if you don't. Stylistically, it's a problem: a maintenance programmer might very well come along and wonder why the close is missing, and add it, possibly breaking something else.
Why do you need to do things this way?
Joined: Jan 11, 2007
Well you guessed it right..!!! I am currently into maintainace activity and wondering why this stream has not been closed. The reason why i am asking this question is that my application is throwing ioException.FileNotFound(Too many open files). The exception are coming when ever a reading or writting function is being performed in the system. System is throwing ioException.FileNotFound(Too many open files) for the files even which are present at the desired location and available for reading. The load method is used very frequently and belive could be one of the reasons for (Too many open files) as the stream is not being closed and the system runs out of streams. Any idea about what could be the reason for the given problem.