ptg7068951
WHAT YOU’LL LEARN IN
THIS HOUR:
.Reading bytes from a file
into a program
.Creating a new file on your
computer
.Saving an array of bytes to
a file
.Making changes to the
data stored in a file
Thereare numerous ways to represent data on a computer. You already
have worked with one by creating objects. An objectincludes data in the
form of variables and references to objects. It also includes methods that
use the data to accomplish tasks.
To work with other kinds of data, such as files on your hard drive and doc-
uments on a web server, you can use the classes of the java.iopackage.
The “io” part of its name stands for “input/output” and the classes are
used to access a source of data, such as a hard drive, CD-ROM, or the com-
puter’s memory.
You can bring data into a program and send data out by using a communi-
cations system called streams, or objects that take information from one
place to another.
Streams
To save data permanently within a Java program, or to retrieve that data
later, you must use at least one stream.
Astreamis an object that takes information from one source and sends it
somewhere else, taking its name from water streams that take fish, boats,
and industrial pollutants from one place to another.
Streams connect a diverse variety of sources, including computer pro-
grams, hard drives, Internet servers, computer memory, and DVD-ROMs.
After you learn how to work with one kind of data using streams, you are
able to work with others in the same manner.
During this hour, you use streams to read and write data stored in files on
your computer.
HOUR 20
Reading and Writing Files