"

55 Javanotes 9.0, Chapter 11 — Input/Output Streams, Files, and Networking

Chapter 11

Input/Output Streams, Files, and Networking



Computer programs are
only useful if they interact
with the rest of the world in some way. This interaction is referred to as
input/output, or I/O (pronounced “eye-oh”).
Up until now, this book has concentrated on just one
type of interaction: interaction with the user, through either a
graphical user interface or a command-line interface. But the user is only one
possible source of information and only one possible destination for
information. We have already encountered one other type of input/output, since
TextIO can read data from files and write data
to files. However, Java has an input/output framework that provides much
more power and flexibility than does TextIO,
and that covers other kinds of I/O in addition to files. Most important, aside from
files, is that it supports communication over network connections.
In Java, the most common type of input/output involving files and networks is based on
I/O streams, which are objects that support I/O
commands that are similar to those that you have already used.
In fact, standard output (System.out) and
standard input (System.in) are examples of I/O streams.
(Note that I/O streams are not streams in the sense of the stream
API that was covered in Section 10.6.)

Working with files and networks requires familiarity with exceptions, which
were covered in Section 8.3. Many of
the subroutines that are used can throw checked exceptions, which require mandatory
exception handling. This generally means calling the subroutine in a
try..catch statement that can deal with the exception if one
occurs. Effective network communication also requires the use of
threads, which will be covered in Chapter 12.
We will look at the basic networking API in this chapter, but
we will return to the topic of threads and networking in Section 12.4.


Contents of Chapter 11:

License

ITP 220 Advanced Java Copyright © by Amanda Shelton. All Rights Reserved.