Chapter 10. Input/Output Facilities
In this chapter,
we’ll continue our exploration of
the Java API by looking at many of the classes in the
java.io package. Figure 10.1
shows the class hierarchy of the java.io package.

Figure 10-1. The java.io package
We’ll start by looking at the stream classes in
java.io; these classes are all subclasses of the
basic InputStream,
OutputStream, Reader, and
Writer classes. Then we’ll examine the
File class and discuss how you can interact with
the filesystem using classes in java.io. Finally,
we’ll take a quick look at the data compression classes
provided in java.util.zip.
Streams
All fundamental I/O in Java is based on streams. A stream represents a flow of data, or a channel of communication with (at least conceptually) a writer at one end and a reader at the other. When you are working with terminal input and output, reading or writing files, or communicating through sockets in Java, you are using a stream of one type or another. So that you can see the forest without being distracted by the trees, we’ll start by summarizing the classes involved with the different types of streams:
-
InputStream/OutputStream Abstract classes that define the basic functionality for reading or writing an unstructured sequence of bytes. All other byte streams in Java are built on top of the basic
InputStreamandOutputStream.-
Reader/Writer Abstract classes that ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access