What I wanted is to reach EOF
by typing Ctrl + z from command line with BufferedReader
reading from console. The following code does so. But the problem is, it issues a NullPointerException
after reaching EOF
. Is there a way to skip this exception? Or more precisely, what is the proper way of reaching EOF
with BufferedReader
reading from console?
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class EOF {
public static void main(String args[]) {
String s = "";
String EOF = "^z";
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
try {
while (!s.equals(EOF)) {
s = read.readLine();
}
} catch (IOException e) {}
}
}