Page 2 of 2 FirstFirst 12
Results 21 to 26 of 26
  1. #21
    Kevinius is offline Member
    Join Date
    Mar 2011
    Posts
    46
    Rep Power
    0

    Default

    Once again...altered my code...brought it closer to the example you provided. It seems to be running smoothly. There are only three lines in the text file, but I wanted to make it dynamic.

    I realized that I had to add a space " " before I print the double values. I understand that it's a TextArea, but why won't it print anything other String?

    Java Code:
     String line = null;
            String[] lines = new String[3];
            Person[] person = new Person[3];
            try {
                Scanner inFile = new Scanner(new FileReader("Information.txt"));
                int i = 0;
                while(inFile.hasNextLine()){
                    line = inFile.nextLine();
                    lines = line.split(" ");
                    Person p = new Person(lines[0], lines[1], Double.parseDouble(lines[2]));
                    person[i] = p;
                    i++;
                }
                inFile.close();
    
                this.jTextArea1.append(" " + person[0].getMonthlyIncome());
    
            } catch (FileNotFoundException ex) {
                Logger.getLogger(Income.class.getName()).log(Level.SEVERE, "File not found!", ex);
            }

  2. #22
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    What happens when you tried this? Errors, if so, please copy/paste the exact error message.

  3. #23
    Kevinius is offline Member
    Join Date
    Mar 2011
    Posts
    46
    Rep Power
    0

    Default

    When that segment is run, it displays the monthly income for the person stored in person[0]. I've since altered the code to display all the data...works like a charm. I just have some slight tweaking to do and it's done.

  4. #24
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I'm glad to have helped. I hope I wasn't too vague, and I hope you learned some things along the way. If you are finished, please mark your thread solved with the thread tools at the top.

  5. #25
    Kevinius is offline Member
    Join Date
    Mar 2011
    Posts
    46
    Rep Power
    0

    Default

    I definitely learned something. That was the first time I've used split method...took awhile to wrap my head around it. Splitting the lines and having them passed into another array was a bit of a pain, but it got the job done.

    It was clear what I needed to do when I read the assignment. When it came to making it happen is where I started scratching my head. I should have known what I was in for when it looked so simple! I appreciate the help sunde887 and Junky! I'm sure that I will probably be back next week with what can only be described as stupid questions! Bear with me! Haha!

  6. #26
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    It's no problem, there are no stupid questions here, we just ask that you ask specific questions and be prepared to do a lot of the problem solving yourself.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Reading Text file to Data type Double
    By orpheus2708 in forum New To Java
    Replies: 17
    Last Post: 04-08-2011, 03:11 AM
  2. Replies: 2
    Last Post: 03-25-2011, 02:36 PM
  3. Problem Reading in data from Text Field
    By markious in forum AWT / Swing
    Replies: 2
    Last Post: 02-12-2010, 02:29 AM
  4. Reading data from a text file
    By Cheguvara in forum New To Java
    Replies: 2
    Last Post: 02-02-2010, 02:33 PM
  5. reading data from text file .. help plz
    By Thug heart in forum New To Java
    Replies: 7
    Last Post: 02-15-2009, 07:29 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •