I/O from the Command Line

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

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

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

Standard Streams

InputStreamReader cin = new InputStreamReader(System.in);



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

why?

This method helps secure password entry in two ways. First, it suppresses echoing, so the password is not visible on the user's screen. Second, readPassword returns a character array, 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.

你可能感兴趣的:(java,html,c,OS,sun)