10: The Java IO system

Bruce Eckel’s Thinking in Java Contents | Prev | Next

IO
system

Creating
a good input/output (IO) system is one of the more difficult tasks for the
language designer.

This
is evidenced by the number of different approaches. The challenge seems to be
in covering all eventualities. Not only are there different kinds of IO that
you want to communicate with (files, the console, network connections), but you
need to talk to them in a wide variety of ways (sequential, random-access,
binary, character, by lines, by words, etc.).

The
Java library designers attacked the problem by creating lots of classes. In
fact, there are so many classes for Java’s IO system that it can be
intimidating at first (ironically, the Java IO design actually prevents an
explosion of classes). There has also been a significant change in the IO library
between Java 1.0

and Java 1.1
.
Instead of simply replacing the old library with a new one, the designers at
Sun extended the old library and added the new one alongside it. As a result
you can sometimes end up mixing the old and new libraries and creating even
more intimidating code.

This
chapter will help you understand the variety of IO classes in the standard Java
library and how to use them. The first portion of the chapter will introduce
the “old” Java 1.0

IO stream library, since there is a significant amount of existing code that
uses that library. The remainder of the chapter will introduce the new features
in the Java 1.1 IO library. Note that when you compile some of the code in the
first part of the chapter with a Java 1.1 compiler you can get a “
deprecated
feature” warning message at compile time. The code still works; the
compiler is just suggesting that you use certain new features that are
described in the latter part of this chapter. It is valuable, however, to see
the difference between the old and new way of doing things and that’s why
it was left in – to increase your understanding (and to allow you to read
code written for Java 1.0
).

More by Author

Must Read