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

前端 未结 4 768
终归单人心
终归单人心 2020-12-03 14:43

I want to make a Java program that reads a Password from STDIN silently. I mean, without outputting any pressed chars to the terminal and keeping it hidden from commandline

4条回答
  •  一个人的身影
    2020-12-03 15:19

    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.

提交回复
热议问题