One of the commonly used classes in the
java.io package is
File. This class is somewhat misleadingly
named, as it represents a filename (or directory name), rather than a
file itself. Because files (and directories) have different naming
conventions under different operating systems, Java provides the
File class to try to hide some of
those differences. The
also defines various methods for operating on files as a whole:
deleting files, creating directories, listing directories, querying
the size and modification time of a file, and so on.
provides methods to manipulate directories and the files within those
directories, it doesn’t provide any methods that manipulate the
contents of the files. In other words, it doesn’t provide any way to
read or write the bytes or characters that are contained in files. In
Java, sequential file I/O is performed through a stream abstraction.
(Random-access file I/O is performed with the
RandomAccessFile class, but sequential I/O
is much more common.)
A stream is simply an object from
which data can be read sequentially or to which data can be written
sequentially. The bulk of the
java.io package consists of stream classes:
there are 40 of them.
OutputStream and their
respective subclasses are objects for reading and writing streams of
Writer and their subclasses are objects for reading and writing streams of Unicode characters. In addition to these stream ...