Skip to content

Instantly share code, notes, and snippets.

@jarek-przygodzki
Last active April 14, 2023 10:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarek-przygodzki/0271ba7bae239cf0b5a61e1ba6741a44 to your computer and use it in GitHub Desktop.
Save jarek-przygodzki/0271ba7bae239cf0b5a61e1ba6741a44 to your computer and use it in GitHub Desktop.
Wait for enter key pressed in Java
/*
* Be beware http://stackoverflow.com/questions/4203646/system-console-returns-null
*/
public static void waitForEnter(String message, Object... args) {
Console c = System.console();
if (c != null) {
// printf-like arguments
if (message != null)
c.format(message, args);
c.format("\nPress ENTER to proceed.\n");
c.readLine();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment