Hello, I have just done a program in Java that reads from a file, stores the values and the prints them, though I have a small problem.
public class Read { public static void main(String[] args) throws Exception { File testFile = new File("me.txt"); Scanner scan = new Scanner(testFile); String name; int phone; name = scan.nextLine(); phone = scan.nextInt(); System.out.println("Name: " + name); System.out.println("Phone: " + phone); scan.close(); } }
I get the error:
Exception in thread "main" java.util.InputMismatchException: For input string: "07983857686" at java.util.Scanner.nextInt(Unknown Source) at java.util.Scanner.nextInt(Unknown Source) at week3.ReadMe.main(ReadMe.java:28)
If I change the phone number from int to String it works, though I wan't to know why? The phone numbers is made up of only numbers, so It must be due to the 0 in front?