Reading Lines
readLine and loops.
The readLine Method
readLine() is the heart of BufferedReader. It reads characters until it hits a line break (Enter), then returns the line as a String.
The returned text does not include the newline character. In this lesson we read single and multiple lines.
String line = br.readLine();Reading One Line
Here is the simplest case: read a name and print a greeting. readLine() blocks (waits) until the user presses Enter.
Because it reads from System.in, this snippet pauses for keyboard input, so it is not auto-runnable here.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
String name = br.readLine();
System.out.println("Welcome, " + name + "!");
}
}