java:system根据输入的内容,然后输出(字节流)

把输入的内容输出来:根据system.in的内容System.out.println输出出来

都是字节流,的形式:

              //限制读取的字符长度
//字节流 InputStream ips = System.in; byte b[] = new byte[20]; System.out.println("请输入:"); int len = ips.read(b); System.out.println( new String(b, 0, len) ); //不限制读取的输入的字符长度

//字节流

//不支持中文
InputStream ipt = System.in; System.out.println("请输入:"); int temp = 0; StringBuffer buff = new StringBuffer(); while( (temp = ipt.read()) !=-1 ) { char c = (char)temp; //判断是否打回车键 if(c == ' ') { break; } buff.append(c); } System.out.println("输入的字符是:" + buff );

  

原文地址:https://www.cnblogs.com/achengmu/p/7209182.html