Writing data to and reading data from files are common tasks for almost any kind of program. Even simple games, such as our MineSweeper game, can benefit from storing information in a file and retrieving it later. (MineSweeper could store the size of game the player last chose and keep track of the best time for each size.) Java provides an extensive collection of classes and interfaces for dealing with files (and associated objects such as directories and drives). The heart of it all is the aptly named and often-used
java.io.File class. “io” stands for input/output.
The first thing to know about working with
java.io.File (I'll call it "
File" from here on) objects is that ...