title: Error in reading a file in java
body: <p>I've been trying to practice I/O file programming and I'm still at the basics. Writing into a file using the java was simple enough but reading to a file is beginning to give me a headache. Here's a simple program I tried to run(btw, I based the program from a book by Liang) .</p>
  
  <pre><code>import java.util.Scanner;
  import java.io.File;
  public class Reading {
  private static Scanner n;
  
  public static void main(String[] args) throws Exception
  {
      File files = new File("samples.txt");
      n = new Scanner(files);
  
      while(n.hasNext())
      {
          String firstName = n.next();
          String mi = n.next();
          String lastName = n.next();
          int score = n.nextInt();
          System.out.println(
          firstName + " " + mi + " " + lastName + " " + score);
      }
  
      n.close();
  }
  
  }
  </code></pre>
  
  <p>Here's the error:</p>
  
  <pre><code>Exception in thread "main" java.util.NoSuchElementException
  at java.util.Scanner.throwFor(Unknown Source)
  at java.util.Scanner.next(Unknown Source)
  at java.util.Scanner.nextInt(Unknown Source)
  at java.util.Scanner.nextInt(Unknown Source)
  at OOPFinals.Reading.main(Reading.java:17)
  </code></pre>
  
  <p>How do I make this program work?
  Help!</p>