Ignore last specified character in a File
<p>I have this section of code:</p>

<pre><code>int numberStars =0;
int counter =0;

while (file.hasNext()) {
  String contents = file.next();
  {             
    if (contents.contains("*")) {
      numberStars = counter;                    
      continue;
    }
    counter++;              
  }
}
</code></pre>

<p>So if I have a text file containing something like</p>

<p>ha de fa * la we * ba *</p>

<p>The output will be 3,5,6.  How do I change this loop so that the last * is not counted (so the 6 won't be present), and also how would I ensure, that each time a value is assigned to numberStars, that value is then used in another part of the method?</p>

<p>Thanks a lot.</p>
