Programming Example 11: File Input


This program illustrates some important concepts related to file input. As you study this code, look for the following important pieces of code:

  1. The declaration of the StreamWriter object.
  2. Reading each line of the file into a string.
  3. Checking to make sure that the string just read is not null.
  4. Using the Split method to break up the elements of data on each line.
  5. Using the Parse method to convert a string into an integer.
  6. Reading until the a null string is returned from the ReadLine( ) method.
  7. Converting a time in minutes and seconds into seconds.
  8. Sorting times and runner's names
  9. breaking a time back up into minutes and seconds.

To run this program, be sure that the file included here is stored in the same place as the executable. Study the code in this program carefully, and then look at the program's output.

The data file for this program is results.txt

The problem statement for this program is located here.

The example program is located here.  An executable of this program can be found here.