title: java: Read text file and store the info in an array using scanner class
body: <p>I have a text file include Student Grades like:</p>
  
  <pre><code>Kim $ 40 $ 45
  Jack $ 35 $ 40
  </code></pre>
  
  <p>I'm trying to read this data from the text file and store the information into an array list using Scanner Class.  Could any one guide me to write the code correctly?</p>
  
  <h3>Code</h3>
  
  <pre><code>import java.io.*;
  import java.util.*;
  
  public class ReadStudentsGrade {
  
  public static void main(String[] args) throws IOException {
  
      ArrayList stuRec = new ArrayList();
      File file = new File("c:\\StudentGrade.txt");
      try {
          Scanner scanner = new Scanner(file).useDelimiter("$");
  
          while (scanner.hasNextLine())
          {
              String stuName = scanner.nextLine();
              int midTirmGrade = scanner.nextInt();
              int finalGrade = scanner.nextInt();
              System.out.println(stuName + " " + midTirmGrade + " " + finalGrade);
          }
      }
      catch (FileNotFoundException e)
      {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <h3>Runtime error:</h3>
  
  <pre><code>Exception in thread "main" java.util.InputMismatchException
      at java.util.Scanner.throwFor(Scanner.java:840)
      at java.util.Scanner.next(Scanner.java:1461)
      at java.util.Scanner.nextInt(Scanner.java:2091)
      at java.util.Scanner.nextInt(Scanner.java:2050)
      at writereadstudentsgrade.ReadStudentsGrade.main(ReadStudentsGrade.java:26)
  </code></pre>