The preceding section showed how to create a sequential-access file using object serialization. In this section, we discuss how to read serialized objects sequentially from a file.
Figure 17.15 reads and displays the contents of the
clients.ser file created by the program in Fig. 17.14. The sample screen captures are identical to those of Fig. 17.11, so they are not shown here. Line 15 creates the
BinaryFormatter that will be used to read objects. The program opens the file for input by creating a
FileStream object (lines 49–50). The name of the file to open is specified as the first argument to the
1 // Fig. 17.15: ReadSequentialAccessFileForm.cs ...