Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Help with some code format

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    2
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with some code format

    Hi Everyone, I'm new to java and working on reading a text file into my java program. The issue with the code I have built is it only reads the text on each line and errors if there is more that one text on the line. Looking for some advice.

    Here is the txt reader,
    public boolean readInterestRates() { //start
    boolean status = false;

    try { //start
    FileReader fis = new FileReader(new File("loanterms.txt"));
    BufferedReader br = new BufferedReader(fis);
    String line = null;

    int i = 0;
    while ((line = br.readLine()) != null) {
    rates[i] = Double.parseDouble(line);
    i++;
    }
    fis.close();
    status = true;
    } catch (Exception e) { //start
    JOptionPane.showMessageDialog(this, "File Read Error!!!");
    status = false;
    } //end


    I need it to read 1 2 3 4 5, and let me choose one of them, right now I can only get it to read
    1
    2
    3
    4
    5
    from the text file. I believe it has something to do with my rates[i] = Double.parseDouble(line); but can't figure out how to correct it.


    Thanks.


  2. #2
    Junior Member
    Join Date
    May 2011
    Posts
    2
    My Mood
    Confused
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with some code format

    I've tried the split but I just can seem to get it in right.

Similar Threads

  1. date format
    By arunjib in forum Java Theory & Questions
    Replies: 4
    Last Post: March 12th, 2011, 12:42 PM
  2. How to set the format of a udp packet ?
    By Mezzo in forum Java Networking
    Replies: 0
    Last Post: January 19th, 2011, 05:43 PM
  3. Format Problems
    By maximus20895 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 27th, 2010, 09:48 PM
  4. How to format?
    By maximus20895 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 15th, 2010, 01:07 PM
  5. [SOLVED] Help with code, Says number is NaN and i cant format it
    By NewGuy in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 4th, 2010, 07:28 PM