Java Reference
In-Depth Information
K.3
The java.io and java.nio.file packages
The java.io and java.nio.file packages contain classes that support input and output
and access to the file system. Many of the input/output classes in java.io are distinguished
by whether they are stream-based (operating on binary data) or readers and writers ( operating
on characters). The java.nio.file package supplies several classes that support convenient
access to the file system.
package java.io.file-Summary of the most important classes and interfaces
interface Serializable
The Serializable interface is an empty interface requiring no code to be
written in an implementing class. Classes implement this interface in order to
be able to participate in the serialization process. Serializable objects
may be written and read as a whole to and from sources of output and input.
This makes storage and retrieval of persistent data a relatively simple pro-
cess in Java. See the ObjectInputStream and ObjectOutputStream
classes for further information.
class BufferedReader
BufferedReader is a class that provides buffered character-based access
to a source of input. Buffered input is often more efficient than unbuffered,
particularly if the source of input is in the external file system. Because it buff-
ers input, it is able to offer a readLine method that is not available in most
other input classes. Key methods are close , read , and readLine .
class BufferedWriter
BufferedWriter is a class that provides buffered character-based output.
Buffered output is often more efficient than unbuffered, particularly if the des-
tination of the output is in the external file system. Key methods are close ,
flush , and write .
class File
The File class provides an object representation for files and folders (directo-
ries) in an external file system. Methods exist to indicate whether a file is read-
able and/or writeable, and whether it is a file or a folder. A File object can be
created for a nonexistent file, which may be a first step in creating a physical
file on the file system. Key methods are canRead , canWrite , createNew-
File , createTempFile , getName , getParent , getPath , isDirec-
tory , isFile , and listFiles .
class FileReader
The FileReader class is used to open an external file ready for reading its
contents as characters. A FileReader object is often passed to the con-
structor of another reader class (such as a BufferedReader ) rather than
being used directly. Key methods are close and read .
class FileWriter
The FileWriter class is used to open an external file ready for writing
character-based data. Pairs of constructors determine whether an existing
file will be appended or its existing contents discarded. A FileWriter ob-
ject is often passed to the constructor of another Writer class (such as a
BufferedWriter ) rather than being used directly. Key methods are close ,
flush , and write .
class IOException
IOException is a checked exception class that is at the root of the excep-
tion hierarchy of most input/output exceptions.
interface Path
The Path interface provides the key methods for accessing information about
a file in the file system. Path is, in effect, a replacement for the older File
class of the java.io package.
Search WWH ::




Custom Search