I have to retrieve numbers from a text file which is as shown in the attachment. I have written the following code snippet just to check if I am able to print the numbers in the file.
Code:
try {
Scanner myFile = new Scanner(new FileReader("C:/Documents and Settings/shikhau/workspace/SanNumber/freelast.txt"));
while (myFile.hasNext()) {
i = myFile.nextInt();
System.out.println(i);
}
}
catch (FileNotFoundException e){
System.out.println("Sorry! This file is not found");
}
I get the following exception:
Code:
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Unknown Source)
at java.util.Scanner.next(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
at java.util.Scanner.nextInt(Unknown Source)
What do I do?