title: Reading integers from text file
body: <p>I am trying to read integers from a <strong>text</strong> file but I failed. 
  (It fails to read even the first integer)</p>
  
  <pre><code>public void readFromFile(String filename) {
      File file = new File(filename);
      try {
          Scanner scanner = new Scanner(file);
          if (scanner.hasNextInt()) {
              int x = scanner.nextInt();
          }
          scanner.close();
  
      } catch (FileNotFoundException e) {
          System.out.println("File to load game was not found");
      }
  }
  </code></pre>
  
  <p>The error I get is: NoSuchElementException.
  The file looks like this: </p>
  
  <pre><code>N,X1,Y1,X2,Y2,X3,Y3
  </code></pre>
  
  <p>While n equals 3 in this example.</p>
  
  <p>I call this method a in the main method like this: </p>
  
  <pre><code>readFromFile("file.txt");
  </code></pre>