i'm trying to read long types from a text file with using readLine()
method of BufferedReader
class and then i parse the first token (which is long type number) with using StringTokenizer
but i'm facing with an exception error which is java.lang.NumberFormatException
this is an example of my text file;
2764841629 Quaroten Ilen
1398844030 Orden Nenama
1185252727 Inja Nenaptin
2370429126 Quaren Inaja
1502141743 Otin Una
1993687334 Quarwennaja Nenoten
1015934104 Polen Meritna
2363674760 Otja Ie
1904629749 Neninin Ordja
3047965620 Algnaja Nenja
here is the code i read from a text file and assing the long value to my long variable
private void registerData() throws FileNotFoundException{
try {
String regPatName;
String regPatSurname;
long regPatID;
FileInputStream fis = new FileInputStream("src\\assignment_3\\injuredPersonList.txt");
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
String line;
while( ( line = reader.readLine() ) != null) {
StringTokenizer st = new StringTokenizer(line, " ");
while(st.hasMoreTokens()){
regPatID = Long.parseLong(st.nextToken());
regPatName = st.nextToken();
regPatSurname = st.nextToken();
Patient regPatient = new Patient(regPatName, regPatSurname, regPatID);
hashMethod(regPatient);
}
}
} catch (IOException ex) {
Logger.getLogger(personTest.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void hashMethod(Patient regPatient){
Long idPat = new Long(regPatient.getPatientID());
int keyID;
keyID = (int) Math.sqrt(Integer.parseInt(idPat.toString().substring(0, 5) + idPat.toString().substring(5, 10))) % (50000);
System.out.println(keyID);
}
and finally this the error which i'm facing;
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "2481765933 Otna"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Long.parseLong(Long.java:419)
at java.lang.Long.parseLong(Long.java:468)
at assignment_3.personTest.registerData(personTest.java:58)
at assignment_3.personTest.<init>(personTest.java:33)
at assignment_3.personTest$1.run(personTest.java:161)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:641)
at java.awt.EventQueue.access$000(EventQueue.java:84)
at java.awt.EventQueue$1.run(EventQueue.java:602)
at java.awt.EventQueue$1.run(EventQueue.java:600)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlContext.java:87)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:611)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
i will be very appreciated if you can help me and also thanks anyway.