I am trying to convert a phone number that is input from a file with dashes in the form of a string to a Long using Long.parseLong(). But I keep getting a number format exception and I cannot figure out why.
Heres whats in my main:
File g = new File("phonenumbers.txt");
Scanner phoneInput = null;
try {
phoneInput = new Scanner(g);
}
catch(FileNotFoundException e) {
System.out.println("FNF");
}
Contact[] contacts = new Contact[1000];
contacts[0] = new Contact(nameInput.nextLine(), Long.parseLong(phoneInput.nextLine()));
System.out.println(contacts[0]);
The first line in the file is "486-686-8308"
My hope is to turn them in to a long so I can sort them using a selection sort method. Here is the error:
Exception in thread "main" java.lang.NumberFormatException: For input string: "486-685-8308"
at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:68)
at java.base/java.lang.Long.parseLong(Long.java:699)
at java.base/java.lang.Long.parseLong(Long.java:824)
at pkgfinal.Final.main(Final.java:41)