The general approach to
input and output (I/O) from a Java program is to:
Open the stream
While there is data to read or write
read and process data, or write data
}
Close the stream
The stream classes for I/O are grouped together in a Java package called java.io. A package is just a
collection of related classes. One can create packages of one??™s own classes, but we will not be describing that
in this brief introduction to the language. The reason to mention the package name here is that a programmer
must import a package in order to take advantage of the classes within it. In order to use the stream classes
we will soon discuss, your program must have a statement at the very beginning, even before the class
statement, that says,
import java.io.*;
The asterisk means to import all the classes in the package. If the programmer wants only one of the
classes, the programmer can substitute the class name for the asterisk. Usually one simply types the line as we
have shown it.
The stream classes in Java are divided into two great categories: Reader/Writer and InputStream/
OutputStream. If the class is in the Reader/Writer category, it is a stream for reading and writing character
data??”letters, numbers, and symbols.
Pages:
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239