Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7615813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:44:10+00:00 2026-05-31T02:44:10+00:00

i’m trying to read long types from a text file with using readLine() method

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T02:44:11+00:00Added an answer on May 31, 2026 at 2:44 am

    You probably have a tab character instead of spaces to separate your fields. Add the tab to your set of delimiters (" \t").

    Also, always close your streams and readers in a finally block (only the outermost one must be closed: closing the BufferedReader will close the InputStreamReader, which will close the FileInputStream).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a text area in my form which accepts all possible characters from
i want to parse a xhtml file and display in UITableView. what is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to render a haml file in a javascript response like so:
I have a reasonable size flat file database of text documents mostly saved in
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.