Java Reference
In-Depth Information
15
Files, Streams and Object
Serialization
Consciousness … does not
appear to itself chopped up in
bits. … A “river” or a “stream”
are the metaphors by which it is
most naturally described.
—William James
Objectives
In this chapter you'll:
Create, read, write and
update files.
■
Retrieve information about
files and directories using
features of the NIO.2 APIs.
■
Learn the differences between
text files and binary files.
■
Use class
Formatter
to
output text to a file.
■
Use class
Scanner
to input
text from a file.
■
Write objects to and read
objects from a file using
object serialization, interface
Serializable
and classes
ObjectOutputStream
and
ObjectInputStream
.
■
Use a
JFileChooser
dialog
to allow users to select files or
directories on disk.
■