---
title: "I/O from the Command Line"
author: "wutao8818"
date: "2009-07-01T11:40:59Z"
tags: ["C", "HTML", "Java", "OS", "SUN"]
slug: "i-o-from-the-command-line"
draft: false
lastmod: "2009-07-01T11:40:59Z"
id: 418153
url: "https://wutaoo.iteye.com/blog/418153"
---

<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**


```java
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. 


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

```



```java
System.console()
```

这个对象有可能返回一个null。原因是 not permitted / OS doesn't support them / or because the program was launched in a noninteractive environment.