CKTIS / Java
io.OutputStream: practical reference
io.OutputStream: practical reference: OutputStream is the base byte-output abstraction; close can release external resources and flush pushes buffered bytes.
Version: Java SE 21 (JLS and Java SE API); examples verified on the repository Java runtime
Syntax
java.io.OutputStreamOutputStream is the base byte-output abstraction; close can release external resources and flush pushes buffered bytes.
Use OutputStream for byte output, adding buffering, text encoding, or a protocol layer required by the destination format.
write(int) writes only the low eight bits. flush does not necessarily make data durable, and close usually closes the destination.
Writing an empty array changes nothing. Failure can follow a partial write; behavior after close belongs to the concrete implementation.
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.OutputStream output = new java.io.ByteArrayOutputStream();
output.write(65);
System.out.println(((java.io.ByteArrayOutputStream) output).size());
}
}
Result
1
The example exercises the documented element in a small deterministic program and compares exact standard output.