13.5. Sequential Versus Random Access Files

The error log program presented in Listing 13-3s and 13-4 writes textual data to a disk file named ErrorLog.txt. If the log file doesn't exist, it is created and the new data is written to the file. If the file exists and already has information stored in it, new data is appended to the end of the existing file. Over the years, this file could grow fairly large if errors continue to be added. Typically, when reading a text file, the reading program starts at the beginning of the file and reads the data in the file to the end.

13.5.1. Sequential Files

The process of continually adding new data to the end of an existing file creates what is called a sequential file. With sequential files, new data is added on to the end of the file. There are no gaps in the data. Indeed, one of the advantages of sequential files is that they are dense. That is, every byte of storage space in a sequential file is filled with a piece of information.

Sequential files are like the old cassette music tapes. If you like song number nine on the tape, you had to fast-forward the tape to that particular song in order to play it. If you were good at it, you could press the fast-forward button on the cassette player, count the required number of seconds in your head, and then press the play button. With practice, you could get pretty close to your desired song. The DVD players of today make this "timed search" seem pretty archaic. You simply skip over the tracks ...

Get Beginning C# 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.