I'm getting a NullPointerException in java (at this line :FileReader fstream = new FileReader(fileName)) when I try to read a text file line by line and store them in an arraylist with this code :
public ArrayList<String> StoreLineByLine(String fileName) throws IOException {
String str;
ArrayList<String> Line = new ArrayList<String>();
FileReader fstream = new FileReader(fileName);
BufferedReader myFileReader = new BufferedReader(fstream);
while ((str = myFileReader.readLine()) != null) {
Line.add(str);
}
myFileReader.close();
return Line;
}
Could anyone help me understand the problem ? Thanks a lot !