GIN222
Applied programming for engineers
Files and Streams
• When information is stored in a separated file,
a program needs to open a stream on it in
order to be able read it.
• A program can also open a stream to write in
a file.
Files and Streams
• In java the java.io package is available and
offers a collection of stream classes for
reading and writing.
• To use these classes, a program needs to
import the java.io package.
• The stream classes are divided into two class
hierarchies, based on the data type (either
characters or bytes) on which they operate
Character Stream and Byte Stream.
Files and Streams
• Reader and Writer are the abstract
superclasses used for 16-bit character streams
in java.
• To read and write 8-bit bytes, programs
should use the byte streams, descendents of
InputStream and OutputStream, typically used
to read and write binary data such as images
and sounds.
Files and Streams
• We are only interested in the manipulation of
text files.
• The Reader and the Writer allowing only the
manipulation of one character at a time, it is
often better to use the BufferedReader and
the BufferedWriter.