1 import java.io.Console;
2
3 public class PasswordColsole {
4 /**
5 * @param args
6 */
7 public static void main(String[] args) {
8 Console console = System.console();
9 if (console == null) {
10 System.err.println("Console not available");
11 return;
12 }
13 String username = console.readLine("Enter username: ");
14 String password = new String(console.readPassword("Enter password: "));
15 System.out.println("username=" + username);
16 System.out.println("username=" + password);
17 }
18 }
运行CMD,到class文件所在路径,
运行 java PasswordColsole
Enter username: 123
Enter password:
username=123
username=a
大家可以看到,造输入密码的时候密码不会回显.
posted on 2007-01-03 09:51
交口称赞 阅读(1343)
评论(2) 编辑 收藏 所属分类:
Java6