NOTE
Basic Streams
Byte streams with InputStream and OutputStream, and character streams with Reader and Writer.
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.
Discussion
Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub