Let’s start with the very basics 🙂
What is a Stream?
A stream is a communication channel used to transfer data items in succession.
A stream can connect to kinds of sources and destinations, including disk files, devices, other programs, and memory arrays.
What are I/O Streams?
You can either read from a stream or write to a stream. A stream is connected to a data source or a data destination.
Input(I) Stream – The InputStream is used to read data from a source.
Output(O) Stream – The OutputStream is used for writing data to a destination.
Types of Streams
Byte Streams: Byte based (reading and writing bytes). Byte streams perform input and output of 8-bit bytes.
Character Streams: Character based (reading and writing characters). Java Character streams are used to perform input and output for 16-bit unicode characters.
The Unicode Standard is the universal character-encoding standard used for representation of text for computer processing.
Note:
Using byte streams is the lowest level of I/0, so if you are reading or writing character data the best approach is to use character streams. Other stream types are built on top of byte streams.
The Java IO API
The java.io package contains many classes that your programs can use to read and write data. The most typical sources and destinations of data are these:
- Files
- Pipes
- Network Connections
- In-memory Buffers (e.g. arrays)
- System.in, System.out, System.error