NOTE
Basic Streams
InputStream.read reads bytes and returns -1 at the end of the stream. These notes examine basic stream behavior through single-byte and bulk reads.
This is a historical learning note and may contain outdated or incomplete understanding.
Bytes
InputStream
read
Returns one byte of content read from the InputStream.
After all data has been read, it returns -1. -1 is an int, not a byte or char; these are different.
read(byte[])
Attempts to read as many bytes as the capacity of the given byte array. The return value indicates how many bytes were actually read.
OutputStream
write(byte)
Only the first byte of the int value is written; the remaining bits are ignored.
write(byte[])
Writes all data in the byte array to the output stream.
flush()
Flushes data from the buffer to disk.
Characters
Reader
read
Returns the character that was read as an int value between 0 and 65535. Returns -1 when the end is reached.
It reads one or more bytes according to the file encoding.
Writer
write
Writes the low 16 bits to the Writer.
Drag to pan, scroll to zoom, and click a node to expand or collapse it. Large maps start with deeper levels collapsed; click nodes to expand them.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub