/** * @author chinajash */ public class ConsoleTest { public static void main(String[] args) { Console console = System.console();//获得Console实例 if(console!=null){//判断console是否可用 String user = new String(console.readLine("Enter user:")); //读取整行字符 String pwd = new String(console.readPassword("Enter passowrd:")); //读取密码,密码输入时不会显示 console.printf("User is:"+user+"\n"); console.printf("Password is:"+pwd+"\n"); }else{ System.out.println("Console is unavailable"); } } } |
Enter user:chinajash Enter passowrd: User is:chinajash Password is:chinajash |
·Java初学者专区 | ·Java高级技术 | ||
·Java图像与多媒体 | ·Java网络编程 | ||
·Eclipse | ·Hibernate | ||
·Spring | ·Struts | ||
·Java设计模式 | ·EJB开发 |