Answer the question
In order to leave comments, you need to log in
How to close unreferenced streams in Java?
For example, I need to read only one line. I do this (of course, maybe it's not possible to do this):
String s = (new BufferedReader(new InputStreamReader(System.in))).readLine();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
reader.close();
Answer the question
In order to leave comments, you need to log in
Everything is pretty simple.
Those. BufferedReader.close() will also free all resources by itself.
To understand exactly, look here the source on line 520.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question