Java Reference
In-Depth Information
Figure 10-1. java.io classes
Unicode itself doesn't solve the entire problem. Many of these human languages were used
on computers long before Unicode was invented, and they didn't all pick the same represent-
ation as Unicode. And they all have zillions of files encoded in a particular representation
that isn't Unicode. So routines are needed when reading and writing to convert between
Unicode
String
objects used inside the Java machine and the particular external representa-
tion in which a user's files are written. These converters are packaged inside a powerful set
of classes called
Reader
s and
Writer
s.
Reader
s and
Writer
s should always be used instead
of
InputStream
s and
OutputStream
s when you want to deal with characters instead of
bytes. We'll see more on this conversion, and how to specify which conversion, a little later
in this chapter.
See Also
One topic
not
addressed in depth here is the Java New I/O package (a poor choice of name: it
was “new” in Java SE 1.4). NIO is more complex to use, and the benefits accrue primarily in
large-scale server-side processing.
Printing All Occurrences of a Pattern
provides one ex-
ample of using NIO. The NIO package is given full coverage in the topic
Java NIO
by Ron
Hitchens (O'Reilly).
Another issue not addressed here is hardcopy printing. Java's scheme for printing onto paper
uses the same graphics model as is used in AWT, the basic Window System package. For this
reason, I defer discussion of printing to
Chapter 12
.
Another topic not covered here is that of having the read or write occur concurrently with
other program activity. This requires the use of threads, or multiple flows of control within a
single program. Threaded I/O is a necessity in many programs: those reading from slow
devices such as tape drives, those reading from or writing to network connections, and those
with a GUI. For this reason, the topic is given considerable attention, in the context of multi-
threaded applications, in
Chapter 22
.