CKTIS / Java
io.StringReader: practical reference
io.StringReader: practical reference: StringReader presents a String as a character Reader without external I/O.
Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Syntax
java.io.StringReaderStringReader presents a String as a character Reader without external I/O.
Use StringReader to adapt an existing String to a parser or test API that consumes Reader without owning an external resource.
Reads count char units and can split surrogate pairs. Reads after close throw IOException; mark/reset are supported.
An empty String immediately returns -1. skip stays within bounds and reset can return to the initial mark while open.
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.StringReader("Java")) { System.out.println((char) reader.read()); }
}
}
Result
J
The example exercises the documented element in a small deterministic program and compares exact standard output.