Java Reference
In-Depth Information
10
File I/O
As a leaf is carried by a stream, whether the stream ends in a lake or in
the sea, so too is the output of your program carried by a stream, not
knowing if the stream goes to the screen or to a file.
WASHROOM WALL OF A
COMPUTER SCIENCE DEPARTMENT (1995)
Introduction
In this chapter, we explain how you can write your programs to take input from a
file and send output to a file. This chapter covers the most common ways of doing
file I/O in Java. However, it is not an exhaustive study of Java I/O classes. The Java
I/O class library contains bewilderingly many classes and an exhaustive treatment of
all of them would be a book by itself.
Prerequisites
You need only some of Chapter 9 on exception handling to read this chapter. You do
not need Chapters 6, 7, or 8 on arrays, inheritance, and polymorphism, except in the
final subsection, which covers writing and reading of arrays to binary files. If you have
not yet covered some basic material on one-dimensional arrays, you can, of course,
simply omit this last subsection.
You may postpone all or part of this chapter if you wish. Nothing in the rest of this
book requires any of this chapter.
10.1
Introduction to File I/O
Good Heavens! For more than forty years I have been speaking prose
without knowing it.
MOLIÈRE,
Le Bourgeois Gentilhomme
In this section we go over some basic concepts about file I/O before we go into any
Java details.
Search WWH ::




Custom Search