🧠 Let’s walk through the types of input and output streams in Java — these are part of the traditional java.io package.
Java organizes streams into two main categories:
✅ 1. Byte Streams (InputStream
/ OutputStream
)
Used for binary data: images, audio, video, etc.
Input Stream Class | Description |
---|
InputStream (abstract) | Base class for byte input |
FileInputStream | Reads bytes from a file |
BufferedInputStream | Adds buffering for performance |
ByteArrayInputStream | Reads bytes from a byte array |
DataInputStream | Reads Java primitives (int, double, etc.) |
ObjectInputStream | Reads serialized objects |
PipedInputStream | Reads data written by another thread |
Output Stream Class | Description |
---|
OutputStream (abstract) | Base class for byte output |
FileOutputStream | Writes bytes to a file |
BufferedOutputStream | Buffers output for performance |
ByteArrayOutputStream | Writes to byte array in memory |
DataOutputStream | Writes Java primitives |
ObjectOutputStream | Writes serialized objects |
PipedOutputStream | Connected to PipedInputStream |
✅ 2. Character Streams (Reader
/ Writer
)
Used for text data: characters, strings, etc.
Reader Class | Description |
---|
Reader (abstract) | Base class for character input |
FileReader | Reads text from a file |
BufferedReader | Reads text efficiently (line-by-line) |
CharArrayReader | Reads from a char array |
StringReader | Reads characters from a string |
InputStreamReader | Bridges InputStream to Reader |
Writer Class | Description |
---|
Writer (abstract) | Base class for character output |
FileWriter | Writes text to a file |
BufferedWriter | Buffers text output |
CharArrayWriter | Writes to a char array |
StringWriter | Writes to a string buffer |
OutputStreamWriter | Bridges OutputStream to Writer |
🔧 Bridging Streams (Character ↔ Byte)
Bridge Class | Use Case |
---|
InputStreamReader | Converts InputStream to Reader (bytes → chars) |
OutputStreamWriter | Converts Writer to OutputStream (chars → bytes) |
🧠 Summary
Type | Base Classes | Data Type | Common Uses |
---|
Byte Stream | InputStream / OutputStream | Binary data | Files, images, raw sockets |
Character Stream | Reader / Writer | Text (Unicode) | Text files, logs, configs |