I've created a simple scanner to count the number of strings in a .txt file. Each string is at nextLine. It counts wrong, every time it gives me the number 297, even there're more than 20 000 strings. The .txt file was created by another program I've coded, it takes links from websites and saves them with FileWriter and BufferedWriter into the .txt file. What could be wrong?
public class Counter {
public static void main(String[] args) throws FileNotFoundException {
Scanner scanner = new Scanner(new File("/Users/myName/Desktop/test.txt"));
String string = scanner.next();
int count = 0;
while (scanner.hasNextLine()) {
string = scanner.next();
count++;
System.out.println(count);
}
}
}
Edit: example of strings:
yahoo.com
google.com
etc.