Results 1 to 5 of 5
  1. #1
    mokonji is offline Member
    Join Date
    Feb 2009
    Posts
    5
    Rep Power
    0

    Default Store textfile data in an array

    I am trying to pull data from a text file(docAddresses.txt) and store the results of each line in different array elements (xmlLocations[]). at the moment, i am getting a "arrayindexoutofboundsexception". as the while-loop is re-entered, it is still assigning the first value of the textfile to var "line".

    Java Code:
    public static String[] fileLocations()
    {
    String xmlLocations[] = null;
    int i = 0;
    
    try
    {
    File file = new File("C:/FYP/Files/docAddresses.txt");
    FileReader fileReader = new FileReader(file);
    BufferedReader in = new BufferedReader(fileReader);
    String line="";
    
    boolean eof= false;
    while(!eof)
    {
    
    line = in.readLine();
    if (line == null)
    {
    eof = true;
    }//end if
    
    else (line != null)
    {
    System.out.println("THE URL INPUT:" +line);
    xmlLocations[i] = line;
    i++;
    }//end else
    }//end while
    }//end try
    
    catch(Exception e)
    {
    System.out.println("Exception caught: "+e);
    }//end catch
    
    
    return xmlLocations;
    
    }//end fileLocations()

    It would be desirable to initialize the array with the first line of the text file but I am not sure how to do this. also the method needs to return a string array...

    if you need more info, please let me know.

    thanks!

  2. #2
    mokonji is offline Member
    Join Date
    Feb 2009
    Posts
    5
    Rep Power
    0

    Default

    never mind! cracked the problem myself. thanks anyway

  3. #3
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Please go to the top of the page and click Thread Tools -> Mark This Thread As Solved.
    -MK12
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by mokonji View Post
    never mind! cracked the problem myself. thanks anyway
    As MK says, please mark the thread as solved.

    And also it's better if you can tell what the error is. Because your thread can be useful to someone too.

  5. #5
    DanielS is offline Member
    Join Date
    Nov 2008
    Posts
    11
    Rep Power
    0

Similar Threads

  1. how to store the data in data base
    By eclipse3.4ide in forum New To Java
    Replies: 5
    Last Post: 02-03-2009, 04:25 AM
  2. Array Assign Values from a Textfile
    By fawadafr in forum Java Applets
    Replies: 6
    Last Post: 11-30-2008, 12:10 AM
  3. How to read data from excel and store it in db
    By saran123 in forum New To Java
    Replies: 5
    Last Post: 10-03-2008, 10:19 AM
  4. How to create folder(s) and store data?
    By Grom in forum New To Java
    Replies: 2
    Last Post: 08-20-2008, 09:01 AM
  5. how to use btree to store data
    By fred in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 05:52 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
  •