title: How to reset Scanner?
body: <p>I want to read a text file and put each line in a String (array of Strings). However that requires scanning file twice, one to figure out how many line are there and another time to create an array of strings of that size. but it throws an error and reset method doesn't seem to work.</p>
  
  <pre><code>    FileReader read = null;
  
      try {
          read = new FileReader("ModulesIn.txt");
          //scan through it and make array of strings - for each line
          Scanner scan = new Scanner(read);
          while(scan.hasNextLine()){
              numOfMods++;
              scan.nextLine();
          }
  
          scan.reset();
  
          lines = new String[numOfMods];
  
          for(int i = 0; i &lt; numOfMods; i++)
              lines[i] = scan.nextLine();
  </code></pre>
  
  <p>This is the snippet of the code that is relevant.</p>