Java.Streams.What types of input/output streams are there?

🧠 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 ClassDescription
InputStream (abstract)Base class for byte input
FileInputStreamReads bytes from a file
BufferedInputStreamAdds buffering for performance
ByteArrayInputStreamReads bytes from a byte array
DataInputStreamReads Java primitives (int, double, etc.)
ObjectInputStreamReads serialized objects
PipedInputStreamReads data written by another thread
Output Stream ClassDescription
OutputStream (abstract)Base class for byte output
FileOutputStreamWrites bytes to a file
BufferedOutputStreamBuffers output for performance
ByteArrayOutputStreamWrites to byte array in memory
DataOutputStreamWrites Java primitives
ObjectOutputStreamWrites serialized objects
PipedOutputStreamConnected to PipedInputStream

✅ 2. Character Streams (Reader / Writer)

Used for text data: characters, strings, etc.

Reader ClassDescription
Reader (abstract)Base class for character input
FileReaderReads text from a file
BufferedReaderReads text efficiently (line-by-line)
CharArrayReaderReads from a char array
StringReaderReads characters from a string
InputStreamReaderBridges InputStream to Reader
Writer ClassDescription
Writer (abstract)Base class for character output
FileWriterWrites text to a file
BufferedWriterBuffers text output
CharArrayWriterWrites to a char array
StringWriterWrites to a string buffer
OutputStreamWriterBridges OutputStream to Writer

🔧 Bridging Streams (Character ↔ Byte)

Bridge ClassUse Case
InputStreamReaderConverts InputStream to Reader (bytes → chars)
OutputStreamWriterConverts Writer to OutputStream (chars → bytes)

🧠 Summary

TypeBase ClassesData TypeCommon Uses
Byte StreamInputStream / OutputStreamBinary dataFiles, images, raw sockets
Character StreamReader / WriterText (Unicode)Text files, logs, configs
This entry was posted in Без рубрики. Bookmark the permalink.

Leave a Reply

Your email address will not be published.