How to use Scanner to read silently from STDIN in Java?

The class java.io.Console may be useful:

System.console().readPassword();

This reads a sequence of chars from the console, without echoing anything.
Note that it only works when you launch your java application with a real console. Otherwise, System.console() returns null.

Leave a Comment