Count each new word in a text file
I wrote a method that adds 1 to an int called total each time it sees a new word:
public int GetTotal() throws FileNotFoundException{
int total = 0;
Scanner s = new Scanner(new BufferedReader(new FileReader("Particles/Names.txt")));
while(s.hasNext()){
if(s.hasNext()){
total++;
}
}
return total;
}
Is that the right way to write it?