这是JDK1.5后的新功能,虽然它属于IO,但用得很少,在此总结一些粗浅的认识:
1. Console对象
Console对象的产生,是依赖于是否有控制台,所以,应该说只能在命令行下,才可以NEW出Console对象, 在ECLIPSE集成软件中,应该没有Console对象产生
2. Console常用方法
readPassword("%s", "pw: ")
c.readLine("%s", "input: ")
3.实例
public class Console1 {
public static void main(String[] args) {
Console c = System.console();
char[] pw;
if(c == null) return;
//readPassword() returns char[];
pw = c.readPassword("%s", "pw: ");
//readPassword always disables echoing, so there is no print even calling println;
System.out.println("pw="+pw.toString());
System.out.println(c.readLine("%s", "input: "));
}
}
C:\Users\jocelynl\Desktop\development\java>javac Console1.java
C:\Users\jocelynl\Desktop\development\java>java Console1
pw:
input: aaaa
aaaa