Hide input on command line

后端 未结 5 1531
清酒与你
清酒与你 2020-11-27 16:08

I know that command line interfaces like Git and others are able to hide input from a user (useful for passwords). Is there a way to programmtically do this in Java? I\'m ta

5条回答
  •  日久生厌
    2020-11-27 17:00

    JLine 2 may be of interest. As well as character masking, it'll provide command-line completion, editing and history facilities. Consequently it's very useful for a CLI-based Java tool.

    To mask your input:

    String password = new jline.ConsoleReader().readLine(new Character('*'));
    

提交回复
热议问题