Answer the question
In order to leave comments, you need to log in
Do I need to close the I/O stream or does it close automatically?
The examples below read a string from the keyboard in two slightly different ways.
String file = new BufferedReader(new InputStreamReader(System.in)).readLine();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String file = reader.readLine();
reader.close();
Answer the question
In order to leave comments, you need to log in
It is recommended to use try-with-resources
try (BufferedReader reader =
new BufferedReader(new InputStreamReader(System.in))) {
String file = reader.readLine();
} catch (IOException e) {
e.printStackTrace();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question