✅ Main Classes of Input/Output Streams
🔹 1. Byte Streams
Use these for binary data (files, images, audio, etc.)
📥 Input Streams (read bytes):
InputStream
(abstract base class)FileInputStream
– reads bytes from a fileBufferedInputStream
– adds bufferingByteArrayInputStream
– reads from a byte arrayDataInputStream
– reads primitive types (int, double, etc.)ObjectInputStream
– reads serialized Java objectsPipedInputStream
– used for inter-thread communication
📤 Output Streams (write bytes):
OutputStream
(abstract base class)FileOutputStream
– writes bytes to a fileBufferedOutputStream
– adds bufferingByteArrayOutputStream
– writes to a byte arrayDataOutputStream
– writes primitivesObjectOutputStream
– writes serialized objectsPipedOutputStream
– connects toPipedInputStream
🔹 2. Character Streams
Use these for text (Unicode characters)
📥 Readers (read characters):
Reader
(abstract base class)FileReader
– reads from a fileBufferedReader
– efficient line-by-line readingCharArrayReader
– reads from a char arrayStringReader
– reads from a stringInputStreamReader
– bridges byte → character stream
📤 Writers (write characters):
Writer
(abstract base class)FileWriter
– writes to a fileBufferedWriter
– buffered writingCharArrayWriter
– writes to char arrayStringWriter
– writes to stringOutputStreamWriter
– bridges character → byte stream
🧠 Summary Table
Category | Input (Read) | Output (Write) |
---|---|---|
Byte Streams | InputStream and subclasses | OutputStream and subclasses |
Char Streams | Reader and subclasses | Writer and subclasses |