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