You’ve already learned how to read and write data in files using file input streams and file output streams. That’s not all there is to files. Files can be created, moved, renamed, copied, deleted, and otherwise manipulated without respect to their contents. Files are also often associated with meta-information that’s not strictly part of the contents of the file, such as the time the file was created, the icon for the file, the permissions that determine which users can read or write to the file, and even the name of the file.
While the abstraction of the contents of a file as an ordered
sequence of bytes used by file input and output streams is almost
standard across platforms, the
is not. The
java.io.File class attempts to provide
a platform-independent abstraction for common file operations and
meta-information. Unfortunately, this class really shows its Unix
roots. It works well on Unix, adequately on Windows and
OS/2—with a few caveats—and fails miserably on the
Macintosh. Java 2 improves things, but there’s still a lot of
history—and coming up with something that genuinely works on
all platforms is an extremely difficult problem.
File manipulation is thus one of the real difficulties of cross-platform Java programming. Before you can hope to write truly cross-platform code, you need a solid understanding of the filesystem basics on all the target platforms. This chapter tries to cover those basics for the major platforms that ...