Java IO Overview
In this text I will try to give you an overview of the classes in the Java IO (
More specifically, I will try to group the classes after their purpose. This grouping should make
it easier for you in the future, to determine the purpose of a class, or find the class you need
for a specific purpose.
Input and Output - Source and Destination
The terms "input" and "output" can sometimes be a bit confusing. The input of one part of an application
is often the output of another. Is an
OutputStream a stream where output is written to,
or output comes out from (for you to read)? After all, an
InputStream outputs its data to
the reading program, doesn't it? Personally, I found this a bit confusing back in the day when I
first started out learning about Java IO.
In an attempt to clear out this possible confusion, I have tried to put some different names on input and output to try to link them conceptually to where the input comes from, and where the output goes.
Java's IO package mostly concerns itself with the reading of raw data from a source and writing of raw data to a destination. The most typical sources and destinations of data are these:
- Network Connections
- In-memory Buffers (e.g. arrays)
- System.in, System.out, System.error
The diagram below illustrates the principle of a program reading data from a source and writing it to some destination:
IO Streams are a core concept in Java IO. A stream is a conceptually endless flow of data. You can either read from a stream or write to a stream. A stream is connected to a data source or a data destination. Streams in Java IO can be either byte based (reading and writing bytes) or character based (reading and writing characters).
The InputStream, OutputStream, Reader and Writer
A program that needs to read data from some source needs an
a Reader. A program that needs to write data to some destination needs an
OutputStream or a
This is also illustrated in the diagram below:
Reader is linked to a source of data. An
Writer is linked to a destination of data.
Java IO Purposes and Features
Java IO contains many subclasses of the
Writer classes. The reason is, that all of these subclasses are addressing various different purposes.
That is why there are so many different classes. The purposes addressed are summarized below:
- File Access
- Network Access
- Internal Memory Buffer Access
- Inter-Thread Communication (Pipes)
- Reading and Writing Text (Readers / Writers)
- Reading and Writing Primitive Data (long, int etc.)
- Reading and Writing Objects
These purposes are nice to know about when reading through the Java IO classes. They make it somewhat easier to understand what the classes are targeting.
Java IO Class Overview Table
Having discussed sources, destinations, input, output and the various IO purposes targeted by the Java IO classes, here is a table listing most (if not all) Java IO classes divided by input, output, being byte based or character based, and any more specific purpose they may be addressing, like buffering, parsing etc.
|Byte Based||Character Based|
|Data - Formatted||PrintStream||PrintWriter|