Java Reference
In-Depth Information
Understanding Streams
This is the first of four chapters devoted to streams and file input/output. This chapter introduces
streams , and deals with keyboard input, and output to the command line.
By the end of this chapter, you will have learned:
What is a stream and what are the main classes that Java provides to support stream operations.
What are stream readers and writers and what they are used for.
How to read data from the keyboard.
How to format data that you write to the command line.
Streams and the New I/O Capability
The package that supports stream input/output is java.io , and it is vast. It defines around fifty classes,
many of which have a large number of methods. It is therefore quite impractical to go into them all in
detail in a topic of this kind. Refer to the java documentation for more information. Our strategy in this,
and the following three chapters, will be to take a practical approach. The idea is to provide an overall
grounding of the concepts involved, and to equip you with enough detailed knowledge to be able to do
a number of specific, useful, and practical things in your programs. These are:
To be able to read data of various kinds from the keyboard.
To be able to create formatted output to the command line.
To be able to read and write files containing basic data.
To be able to read and write files containing objects.
To achieve this, we will give you an overview of what the important stream classes do, and how they
interrelate, together with the classes that operate on streams. We will go into detail selectively, just
exploring the classes and methods that we need to accomplish specific things. We will also be sticking to
the latest and greatest I/O capability in the JDK 1.4, which makes it unnecessary to delve into a lot of
Search WWH ::




Custom Search