Java: manually holding execution

This snippet comes in handy when you want to hang execution of the command line app until user presses ENTER on the keyboard:


BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Waiting for you to press ENTER:");
reader.readLine(); // waiting for user indefinitely until ENTER is pressed

No comments:

Post a Comment