txt file that I am reading into my program line by line. My goal is to display this text with no punctuations and in all lowercase. So far I am able to display this text in this way with the code below however I keep receiving a run-time error of a nullpointer exception at the last line of my "while" expression and I am not sure where my error is. I believe the problem may have been in my boolean while expression and I tried changing input != null
to reader.readLine() != null
with no success. Thank you!
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
public class BinaryTree {
public static void main(String[] args) {
String inputFile = "pg345.txt";
FileReader fileReader = null;
try {
fileReader = new FileReader(inputFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedReader reader = new BufferedReader(fileReader);
String input;
try {
input = reader.readLine().toLowerCase().replaceAll("[^a-zA-Z ]", "").toLowerCase();
System.out.println(input);
while (input != null) {
input = reader.readLine().toLowerCase().replaceAll("[^a-zA-Z ]", "").toLowerCase();
System.out.println(input);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
fileReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}