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.
I get the following exception: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"); }
What do I do?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)




Reply With Quote