Hello
Your code is correct, but it will result in an infinite loop. To stop this, use a condition to break out of the loop. The following code will create a vector of String objects of each line in the file.
public static Vector<String> loadFile(String filename){
Vector<String> strings = new Vector<String>();
try{
FileReader file = new FileReader(filename);
BufferedReader buffer = new BufferedReader(file);
while (true)
{
String line = buffer.readLine();
if (line == null)
break;
else {
strings.add(line);
}
}
buffer.close();
} catch (Exception e) {
System.out.println("Error: " + e.getMessage());
}
return strings;
}
Note that you must always close a file after using it and that the readLine() method will return null if there is no more to read. It is also important to handle any exceptions that by be thrown by the IO classes.
I do not have a IDE on this PC, so my code has been checked by hand.