Java I/O Overview
Java IO is an API that comes with Java that facilitates reading and writing data (input and output). E.g. reading data from a file , from console or over a network etc. and after processing write to a file, console or write response back to network etc.
Java performs I/O through streams. Conceptually, a stream is a flow of data in the form of bytes. The java.io package provides classes that allow you to work with different types of streams.
Get Lavish Jain’s stories in your inbox
Join Medium for free to get updates from this writer.
In Java streams are logically categorized into two types- Byte Stream and Character Stream.
Byte Stream reads and writes data byte by byte (8 bits). InputStream and OutputStream are two abstract classes provided by java that are based on Byte Stream.
Note that most of the applications today use Unicode(UTF-8 or UTF-16) to store text data. It may take one or more bytes to represent a single character in UTF-8. Therefore, when reading text data, a single byte in the data may not correspond to one character in UTF. If you just read one byte at a time of UTF-8 data via a Byte Stream and try to convert each byte into a char, you may not end up with the text you expected.
Character Stream reads and writes data character by character using unicode conventions. Reader and Writer are two abstract classes provided by java that are based on Character Stream.
Note that InputStream, OutputStream, Reader and Writer are just abstract classes and many concrete implementations of these abstract classes are also provided in Java which are covered in detail along with examples in ByteStream and CharacterStream articles .







