OCJP之Console

这是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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值