A stream is a flow of data. Data comes **in** from somewhere (keyboard, file, network), and data goes **out** to somewhere (screen, file, network). Java models both directions with the same idea, which is why almost every I/O class ends in InputStream or OutputStream.
INPUT OUTPUT
your data --> [ stream ] --> program program --> [ stream ] --> destination
InputStream (reads bytes) OutputStream (writes bytes)
Reader (reads characters) Writer (writes characters)The word byte is doing real work here. Java stores text as bytes, and a byte is 8 bits. A character such as the letter A is one byte in plain ASCII, but a character such as é or ध takes more than one byte in UTF-8. That single fact explains most of the confusing class names in this topic.
- Input means data flowing into your program, out means data leaving it.
- The direction and the unit are two separate choices. You can read bytes or characters, and each has its own class family.
- Streams are one-way. An input stream is not an output stream, which is why sockets have two of them.