Name

Package java.io

Synopsis

The java.io package is large, but most of the classes it contains fall into a well-structured hierarchy. Most of the package consists of byte streams—subclasses of InputStream or OutputStream and character streams—subclasses of Reader or Writer. Each of these stream subtypes has a specific purpose, and, despite its size, java.io is a straightforward package to understand and to use. In Java 1.4, the java.io package was complemented by a “New I/O API” defined in the java.nio package and its subpackages. The java.nio package is totally new, although it included some compatibility with the classes in this package. It was designed for high-performance I/O, particularly for use in servers and has a lower-level API than this package does. The I/O facilities of java.io are still quite adequate for most of the I/O required by typical client-side applications.

Before we consider the stream classes that comprise the bulk of this package, let’s examine the important nonstream classes. File represents a file or directory name in a system-independent way and provides methods for listing directories, querying file attributes, and renaming and deleting files. FilenameFilter is an interface that defines a method that accepts or rejects specified filenames. It is used by File to specify what types of files should be included in directory listings. RandomAccessFile allows you to read from or write to arbitrary locations of a file. Often, though, you’ll prefer sequential ...

Get Java in a Nutshell, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.