In this section, we walk you through an example program that stores an array of
Employee records in a text file. Each record is stored in a separate line. Instance fields are separated from each other by delimiters. We use a vertical bar (
|) as our delimiter. (A colon (
:) is another popular choice. Part of the fun is that everyone uses a different delimiter.) Naturally, we punt on the issue of what might happen if a
| actually occurred in one of the strings we save.
Here is a sample set of records:
Harry Hacker|35500|1989|10|1 Carl Cracker|75000|1987|12|15 Tony Tester|38000|1990|3|15
Writing records is simple. Since we write to a text file, we use the
PrintWriter class. We simply write all fields, followed ...