java console

import java.io.Console;

public class Test01 {

	public static void main(String[] args) {
		Console console = System.console();
		if (console != null) {
			String user = new String(console.readLine("Enter User:",
					new Object[0]));
			String pwd = new String(console.readPassword("Enter Password:",
					new Object[0]));
			console.printf("User name is:%s", new Object[] { user });
			console.printf("Password is:%s", new Object[] { pwd });
		} else {
			System.out.println("No Console!");
		}

	}

}

 

不能在Eclipse里面运行,必须在jdk1.6以上运行,用户名输入可见,密码输入不可见

你可能感兴趣的:(java,eclipse)