3、
public class crate{
static String loadStream(InputStream in) throws IOException {
StringBuffer buffer = new StringBuffer();
int n = 1,i=5;
byte[] buf = new byte[n]; // 缓冲区,大小为1字节
while(i>0) {
in.read(buf,0,n);
System.out.println(new String(buf));
buffer.append(new String(buf));
i--;
}
return new String(buffer);
}
public static void main(String[] args) throws IOException {
InputStream in = new BufferedInputStream(System.in);//in必须要初始化一个对象,不能为null
String test = loadStream(in);
System.out.println("result = " + test);
}
}