public static void main(String[] args) throws IOException {
byte c1;
byte c2[]=new byte[3];
byte c3[]=new byte[6];
System.out.print("请输入:");
c1=(byte)System.in.read();
//把读的字符放到c2数组里面
System.in.read(c2);
System.in.read(c3, 0, 6);
//输出刚才读入的字节数据
System.out.println((char)c1);
System.out.write(c2,0,3);
System.out.println();
System.out.write(c3,0,6);
System.out.println();
System.out.println("输入流中还有多余"+System.in.available()+"个字节");
System.in.read();
System.in.read();
System.in.read();
System.out.print("输入流中还有多余"+System.in.available()+"个字节");
}
当我们输入:abcdefg时,点击回车,产生两个字符紧跟在输入的信息后面,一般我们很难注意到,只有通过上面的测试才能发现。
时间上我们点击回车时,产生的字符为:abcdefg(回车)(换行)