当前位置: 代码迷 >> 综合 >> [Java 12 IO] InputStream inputStream = System.in; 的读操作 read() != -1
  详细解决方案

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

热度:19   发布时间:2023-12-14 08:42:41.0
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"));}
}

  相关解决方案