Below is a section of my Reverse Polish Calculator.
If an integer is entered, push it to the stack and, if = is pressed, peek the result. However, I want to a
Try this:
public static void main(String[] args) {
try {
byte[] b = new byte[1024];
for (int r; (r = System.in.read(b)) != -1;) {
String buffer = new String(b, 0, r);
System.out.println("read: " + buffer);
}
} catch (Exception e) {
e.printStackTrace();
}
}
In this case the loop will stop when you press CTRL+D that is because CTRL+D sends an EOF
signal to the System.in
InputStream
which is -1
. That is the case on *nix systems, for Windows system, the EOF
signal is sent using the CTRL+Z key combination