Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

io.Reader: practical reference

io.Reader: practical reference: Reader is the base character-input abstraction; read returns UTF-16 code units or -1 and does not itself select a byte encoding.

Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime

Syntax

java.io.Reader

Reader is the base character-input abstraction; read returns UTF-16 code units or -1 and does not itself select a byte encoding.

Use Reader for decoded characters and choose the Charset at the byte-to-character boundary, such as an InputStreamReader.

read(char[]) can be partial and -1 means EOF. char indexing can split a supplementary code point into surrogate halves.

A zero-length buffer may yield zero. mark/reset are optional, and closing a wrapper can close its source.

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 {
        java.io.Reader reader = new java.io.StringReader("J");
        System.out.println((char) reader.read());
    }
}

Result

J

The example exercises the documented element in a small deterministic program and compares exact standard output.

Sources