This content has been marked as final. Show 7 replies
Same thing will happen whether you close it inside or outside the "method". You can try closing Reader when you've finished using the InputStream.
Yes. But if outside method, caller can have his decision on when to close Reader (In-turn indirectly close InputStream). Currently, he doesn't have any control over it.
The problem is, whenever I close the Reader, InputStream will be closed as well.So don't close it.
This is not my intention. As InputStream is "opened" by the caller. Hence, the closing operation on InputStream shall be done at caller side.So don't close it.
Is there any way I can close the Reader in "method", without closing the InputStream passed by caller?Don't close it.
A very humor answer :)
But, what about resource leak?
I was perfectly serious.
But, what about resource leak?What resource leak? You said the caller is supposed to close the stream. If they don't, it's their problem.
I don't mean the stream passed by caller.
What I mean is the reader being created in "method". As we are creating the reader in "method", isn't we suppose to close the reader to avoid resource leaking?
Closing the reader closes the stream. That's the resource. If you don't want to close it, don't close it, get somebody else to close it. If you're totally fixated on closing everything you create in the same method, close it in the method and solve your problem another way.