标准IO输入输出流
Java提供了三个静态变量
System.in: 为InputStream类型,标准输入流,默认为键盘输入值System.out:为PrintStream类型,标准输出流,默认为控制台输出System.err:为PrintStream类型,代表错误输出流,默认为控制台输出
以下代码实现将键盘输入,输出到控制台,以回车键结束:
package com.perficient.javabasic.test;import java.io.IOException;import java.io.InputStreamReader;import java.io.OutputStreamWriter;public class IOTesting {public static void main(String[] args) throws IOException {int c;InputStreamReader in = new InputStreamReader(System.in);OutputStreamWriter out = new OutputStreamWriter(System.out);System.out.println("Please Enter the strings ended by Enter key:");while ((c = in.read())!= '\n'){out.write(c);}out.close();in.close();}}