如何在控制台将输入的字符显示为星号? 如要在控制台输入管理员密码,请问各位高人要怎样才能显示为星号呢?达人指点指点! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 使用JDK1.6提供的 java.io.Console类,里面有回显char[] readPassword() 从控制台读取密码,禁用回显。 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)); } }} 不过这是不回显的, 如果应用程序需要读取密码或其他安全数据,则它应该使用 readPassword() 或 readPassword(String, Object...),并在执行后手工将返回的字符数组归零,以最大限度地缩短内存中敏感数据的生存期。 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));}}} 面试时技术经理问你:如何处理分页的,该怎样回答呀 求一个正则表达式,如果不用正则表达式也能做到也好 JComponent.setBackground()没有用? 正则式<.*?>为什么不能匹配HTML的注释标签? 对象引用型参数的传递问题 判断周六、周日的奇怪现象,附源码 如何不让toolbar被拖动 MouseEvent问题求救!! 问:下面的错误是什么意思? 谁有JPadPro的注册码,知道怎么注册也行,高分相送 求思路????超市销售管理系统 启动JAVA程序 java -jar ****.jar,那关闭呢?
从控制台读取密码,禁用回显。
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));
}
}
}
不过这是不回显的,
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));
}
}
}