I'm trying to read text from a txt file, but every time I run the code, the first time it works perfectly, and then the second time it gives me a null pointer error on the line with the arrows. It will work again on the same file if I open it, backspace a character and then retype it and save.
Heres the code:
public void readFile() throws IOException{
InputStream stream = this.getClass().getResourceAsStream(filePath+fileName);
BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
String line;
do{
//Read each line of the file
//Each line will correspond to separate entities. End characters will denote the end of an entity's data
//Each line will be read, 'decrypted' and then set into the elements ArrayList
line = reader.readLine();
lines.add(line);
System.out.println(line);
}while(!line.equals("-END_OF_STREAM-")); //<<<<<<<<<<
reader.close();
stream.close();
}
Any help is much appreciated,
Thanks,
Peter