您的位置:首页 > 编程语言 > Java开发

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

2014-06-06 10:48 555 查看
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"));
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐