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".
public static String fileLocations()
String xmlLocations = null;
int i = 0;
File file = new File("C:/FYP/Files/docAddresses.txt");
FileReader fileReader = new FileReader(file);
BufferedReader in = new BufferedReader(fileReader);
boolean eof= false;
line = in.readLine();
if (line == null)
eof = true;
else (line != null)
System.out.println("THE URL INPUT:" +line);
xmlLocations[i] = line;
System.out.println("Exception caught: "+e);
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.