I wrote the following code, which opens a .txt
file and writes its content to the console, but it shows me a NullPointerException
, could you help me on debugging this?
box = new JFileChooser();
returnVal = box.showOpenDialog(null);
if (returnVal == box.APPROVE_OPTION) {
File file = box.getSelectedFile();
}
try {
BufferedReader br = new BufferedReader(new FileReader(file));
while (br.readLine() == null) {
System.out.println(br.readLine());
}
} catch (Exception e1) {
e1.printStackTrace();
}