Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / Java

io.Writer: practical reference

io.Writer: practical reference: Writer is the base character-output abstraction and may buffer data that must be flushed or closed.

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

Syntax

java.io.Writer

Writer is the base character-output abstraction and may buffer data that must be flushed or closed.

Use Writer for character output, selecting Charset only in the byte adapter and buffering repeated small writes.

write(int) keeps only the low 16 bits as a char. flush differs from close, and writing after close usually throws IOException.

append(null) writes the four characters null. Implementations can fail after partial output and may synchronize on their lock object.

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.Writer writer = new java.io.StringWriter();
        writer.append("ok");
        System.out.println(writer);
    }
}

Result

ok

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

Sources