如要在控制台输入管理员密码,请问各位高人要怎样才能显示为星号呢?达人指点指点! 

解决方案 »

  1.   

    使用JDK1.6提供的  java.io.Console类,里面有回显char[] readPassword() 
    从控制台读取密码,禁用回显。 
      

  2.   

    import java.io.*;public class TestConsole{
    public static void main(String[] args) {
    Console console;
    char[] pwd;
    if((console = System.console()) != null && (pwd = console.readPassword("[%s]", "Please Enter Password:")) != null){
    System.out.println(String.valueOf(pwd));
    }
    }

    不过这是不回显的,
      

  3.   

    如果应用程序需要读取密码或其他安全数据,则它应该使用 readPassword() 或 readPassword(String, Object...),并在执行后手工将返回的字符数组归零,以最大限度地缩短内存中敏感数据的生存期。
      

  4.   

    import   java.io.*;public   class   TestConsole{
    public   static   void   main(String[]   args)   {
    Console   console;
    char[]   pwd;
    if((console   =   System.console())   !=   null   &&   (pwd   =   console.readPassword( "[%s] ",   "Please   Enter   Password: "))   !=   null){
    System.out.println(String.valueOf(pwd));
    }
    }