title: How to read and sort a text file?
body: <p>//    I used a java program to read a text file (athlete.txt) and outputs the contents to<br>
  the screen, I now need to write a java program that read and sort athlete.txt by Athlete number ( then prints its data on the screen. The output can be in ascending or descending order. </p>
  
  <pre><code>    import java.io.*;
      import java.util.Scanner;
  
  
      public class AthleteRecords {
      public static void main(String[] args) throws Exception
      {
        Scanner in = new Scanner(new FileReader("athlete.txt"));
          while (in.hasNextLine())
           {
             System.out.println(in.nextLine());
            }
        }
      }
  
  
  
      //Output file
  
      Athlete Number: 4233
      First Name: Peter
      Family Name: Brown
      Class 1 
      Position and points awarded for 100m race: 3  50
      Position and points awarded for 200m race: 2  80
      Position and points awarded for 400m race: 1  100
      Class 2
      Position and points awarded for 100m race: 3  50
      Position and points awarded for 200m race: 4  20
      Position and points awarded for 400m race: 2  80
  
      Athlete Number: 1235
      First Name: Robert
      Family Name: Anderson
      Class 1 
      Position and points awarded for 100m race: 4  20
      Position and points awarded for 200m race: 1  100
      Position and points awarded for 400m race: 2  80
  
      Class 2
      Position and points awarded for 100m race: 2  80
      Position and points awarded for 200m race: 1  100
      Position and points awarded for 400m race: 3  50
  
      Athlete Number: 3248
      First Name: Sean
      Family Name: Thompson
      Class 1 
      Position and points awarded for 100m race: 4  20
      Position and points awarded for 200m race: 1  100
      Position and points awarded for 400m race: 2  80
      Class 2
      Position and points awarded for 100m race: 2  80
      Position and points awarded for 200m race: 1  100
      Position and points awarded for 400m race: 3  50
  </code></pre>