File I/O

There are many ways to handle reading from a file, but the basic steps needed to do so are:

  1. Open the file.
  2. Read through the file (line-by-line, character-by-character, etc) until you reach the end-of-file (EOF) character.
  3. Close the file.

There are many ways to do the second step, including handling reaching the end-of-file.
  1. In the case of this lab, the number of records is given at the beginning of the file. So you could simply read the number of lines specified in the beginning of the file. This, however, is unrealistic, since most files do not specify how many records they contain.
  2. Keep looping until an EOF character is detected, reading the next item on each iteration. This is how file I/O is done in most languages and it is what you will implement in this lab.
  3. In Java, there is an EOFException. You could enclose your file reading logic in a try-catch block that reads records from your file until this exception is caught.