5 Replies Latest reply: Feb 23, 2009 3:58 AM by 807588 RSS

    store values of text file in an array

    807588
      Hi Folks,

      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".

      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()
      if you need more info, please let me know.

      thanks!