Java IO Overview
In this text I will try to give you an overview of the classes in the Java IO (java.io) package. 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.
Here is a list of the topics covered in this text:
- Input and Output - Source and Destination
- Java IO Purposes and Features
- Java IO Class Overview Table
NOTE: This text uses SVG diagrams which not all browsers can show natively. If you cannot see any of the diagrams, and you are using Internet Explorer, you should install the Adobe SVG Reader Plugin. Firefox 3.0.5+ and Chrome users should be fine without this plugin.
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:
A program that needs to read data from some source needs an input stream or Reader. A program that needs to write data to some destination needs an output stream or writer. 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
The Java IO classes, which mostly consists of streams and readers / writers, are addressing various 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, this text will finish off with a table of 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|