This is the data in myFile.txt, the first line has 4 tokens, the second has 3, and the last has 4 tokens. The last token, an int, indicates the persons salary. If no salary, the no integer, and thus one less token.
Peter, 22, m, 1200
Nina, 24, f
Oscar, 40,m, 40000
Obviously the while loop further down, would give me an inputMisMatchException, so is there a good way for reading textfiles where each line my have one extra/less token?
while(input.hasNextLine()) {
String name = input.next();
int age = input.nextInt();
String gender = input.next();
int salary = input.nextInt();
}