Java Scanner won't read through the whole file : <p>So I'm trying to read through a whole file and print its content, which it does. But when I go through it again with a new Scanner to print the content with some section names, it only goes through some of the file.</p>

<p>Here's my code:</p>

<pre><code>import java.util.*;
import java.io.*;


public class FileReader {
   public static void main(String[] args) throws FileNotFoundException {
      Scanner read = new Scanner(new File("sample.txt")); 

      while(read.hasNextLine()) {
         System.out.println(read.nextLine());
      } 
      System.out.println();   

      Scanner read2 = new Scanner(new File("sample.txt")); 
      int numQuestions = read2.nextInt();
      System.out.println("Numbers of questions: " + numQuestions);
      System.out.println();

      while(read2.hasNextLine()) {
         int points, numChoices;
         String question, answer;

         if(read2.next().equals("TF")) {
            points = read2.nextInt();
            System.out.println("Points for TF: " + points); 
            read2.nextLine();  // must be done because it does not consume the \n character
            question = read2.nextLine();
            System.out.println("Question for TF: " + question);    
            answer = read2.next();
            System.out.println("Answer for TF: " + answer);
         }
         else if(read2.next().equals("SA")) {
            points = read2.nextInt();
            System.out.println("Points for SA: " + points);
            read2.nextLine();  // must be done because it does not consume the \n character
            question = read2.nextLine();            
            System.out.println("Question for SA: " + question); 
            answer = read2.next();
            System.out.println("Answer for SA: " + answer);
         }
         else if(read2.next().equals("MC")) {
            points = read2.nextInt();
            System.out.println("Points for MC: " + points);
            read2.nextLine();  // must be done because it does not consume the \n character
            question = read2.nextLine();
            System.out.println("Question for MC: " + question);
            read2.nextLine();
            numChoices = read2.nextInt();
            for(int i = 0; i &lt; numChoices; i++) {
               System.out.println(read2.nextLine());
            }
            answer = read2.next();
            System.out.println("Answer for MC: " + answer); 
         }
      }
   }
}
</code></pre>

<p>Here's the file I'm reading from:</p>

<pre><code>3 
TF 5
There exist birds that can not fly. (true/false) 
true 
MC 10 
Who was the president of the USA in 1991? 
6 
Richard Nixon 
Gerald Ford 
Jimmy Carter 
Ronald Reagan 
George Bush Sr. 
Bill Clinton 
E 
SA 20 
What city hosted the 2004 Summer Olympics? 
Athens
</code></pre>

<p>And here is the output I get:</p>

<pre><code>3 
TF 5
There exist birds that can not fly. (true/false) 
true 
MC 10 
Who was the president of the USA in 1991? 
6 
Richard Nixon 
Gerald Ford 
Jimmy Carter 
Ronald Reagan 
George Bush Sr. 
Bill Clinton 
E 
SA 20 
What city hosted the 2004 Summer Olympics? 
Athens

Numbers of questions: 3

Points for TF: 5
Question for TF: There exist birds that can not fly. (true/false) 
Answer for TF: true
</code></pre>

<p>As you can see, the first <code>Scanner</code> reads through the whole file and prints it. But when I try for the second time with the section names, it only goes through question 1's part.</p>
