The program below prints each character written on standard in, but only after a new-line has been written (at least on my system!).
public class Test {
public static void main(String[] args) throws java.io.IOException {
int c;
while ((c = System.in.read()) != -1)
System.out.print((char) c);
}
}
This prevents people from writing stuff like "Press any key to continue" and forces something like "Press enter to continue."
- What is the underlying reason for this?
- Is it a limitation of Java?
- Is this behavior system-dependent (I'm on Ubuntu)? How does it work on Mac? Windows?
- Is it dependent on the specific terminal I run the application in? (For me it behaves like this in Eclipse and in gnome-terminal)
- Is there a workaround?