[Java 12 IO] InputStream inputStream = System.in; 的读操作 read() != -1

InputStream 的另一种方式读
package com.qunar.basicJava.javase.io;

import java.io.IOException;
import java.io.InputStream;

/**
 * Author: libin.chen@qunar.com  Date: 14-6-5 21:02
 */
public class SystemDemo05 {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        StringBuffer stringBuffer = new StringBuffer();
        System.out.println("请输入内容 : ");
        int temp = 0;
        while <strong>((temp = inputStream.read()) != -1) {</strong>
            char c = (char)temp;
            if (c == '\n') break;
            stringBuffer.append(c);
        }
        System.out.println("输出的内容是 : " + stringBuffer);
        inputStream.close();

        System.out.println(System.getProperty("file.encoding"));
    }
}

posted @ 2014-06-06 10:48  小尼人00  阅读(295)  评论(0编辑  收藏  举报