How do you read the contents of a file into an ArrayList
in Java?
Here are the file contents:
cat
ho
//CS124 HW6 Wikipedia Relation Extraction
//Alan Joyce (ajoyce)
public List addWives(String fileName) {
List wives = new ArrayList();
try {
BufferedReader input = new BufferedReader(new FileReader(fileName));
// for each line
for(String line = input.readLine(); line != null; line = input.readLine()) {
wives.add(line);
}
input.close();
} catch(IOException e) {
e.printStackTrace();
System.exit(1);
return null;
}
return wives;
}