CKTIS / Java
io.BufferedReader: practical reference
io.BufferedReader: practical reference: BufferedReader buffers characters from a Reader and adds readLine; null means end of stream, while an empty line is returned as an empty string.
Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Syntax
java.io.BufferedReaderBufferedReader buffers characters from a Reader and adds readLine; null means end of stream, while an empty line is returned as an empty string.
Use BufferedReader for line-oriented or block character input when buffering should reduce calls to an underlying Reader.
readLine returns null only at end of input; an empty line is the empty String. Closing it closes the wrapped Reader.
A final line need not have a terminator. A mark becomes invalid after reading beyond its readAheadLimit.
The example exercises the documented element in a small deterministic program and compares exact standard output.
Examples
public class Main {
public static void main(String[] args) throws Exception {
try (var reader = new java.io.BufferedReader(new java.io.StringReader("first\nsecond"))) {
System.out.println(reader.readLine());
System.out.println(reader.readLine());
}
}
}
Result
first second
The example exercises the documented element in a small deterministic program and compares exact standard output.