Resetting a .nextLine() Scanner
<p>I am a rank amateur when it comes to Java, so please pardon my question if it seems dumb 
:-P
I have the following code which is designed to count the number of lines in a file:</p>

<pre><code>while (scanNumOfLines.hasNextLine())    
    {
    NumOfLines ++;
    scanNumOfLines.nextLine();
    }
    System.out.println("NumOfLines = "+NumOfLines);
</code></pre>

<p>So it counts fine, but I want to re-use the scanner for another purpose, but the nextLine has moved to the last line of the file, and I want to reset it back to the first line. </p>

<p>(Instead, I had to use another scanner for the other purpose, and to me this seems less elegant than it should be.)</p>

<p>I'm sure there must be a scanner method that resets the counter to zero?</p>

<p>Thanks </p>

<p>CJ</p>
