I/O from the Command Line

[url]http://java.sun.com/docs/books/tutorial/essential/io/cl.html[/url]

The Java platform supports this kind of interaction in two ways: through the Standard Streams and through the Console.

java平台支持2种控制台交互方式。1是通过标准的stream 另外一种就是 console

[b]Standard Streams[/b]

InputStreamReader cin = new InputStreamReader(System.in);



[b]The Console[/b]
[url]http://java.sun.com/javase/6/docs/api/java/io/Console.html[/url]
Console流相对标准流来说是一个更高级的选项。Console类有大部分标准流提供的功能。另外它特别适合用户名密码这样的情况

why?

This method helps secure password entry in two ways. First, it suppresses echoing, so the password is [b]not visible[/b] on the user's screen. Second, readPassword returns a[b] character array[/b], not a String, so the password can be overwritten, removing it from memory as soon as it is no longer needed.


char [] oldPassword = c.readPassword("Enter your old password: ");


System.console()

这个对象有可能返回一个null。原因是 not permitted / OS doesn't support them / or because the program was launched in a noninteractive environment.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值