全屏
Java Console.readPassword()方法示例
Console.readPassword()的语法如下所示。
public char[] readPassword()
示例
在下面的代码显示如何使用Console.readPassword()方法。
import java.io.Console;
// By: w w w.YIIb aI .C om
public class Main {
public static void main(String[] args) throws Exception {
Console cnsl = System.console();
if (cnsl != null) {
String alpha = cnsl.readLine("Name: ");
System.out.println("Name is: " + alpha);
char[] pwd = cnsl.readPassword("Password: ");
System.out.println("Password is: " + pwd);
}
}
}
上面的代码生成以下结果。
F:websiteyiibaiworkspsrc>javac Main.java
F:websiteyiibaiworkspsrc>java Main
Name: yes
Name is: yes
Password:
Password is: [C@7d4991ad
分享到:
0评论