157.用Read4读取N个字符
/*** The read4 API is defined in the parent class Reader4.* int read4(char[] buf4);*/public class Solution extends Reader4 {/*** @param buf Destination buffer* @param n Number of characters to read* @return The number of actual characters read*/public int read(char[] buf, int n) {//int read4(char[] buf)。根据定义,方法 read4 每次读取 k 个字符(k 不超过 4),并将读取的字符存入其输入参数 buf 中int index = 0;char[] tmp = new char[4];while(index < n){int count = read4(tmp);if(count == 0){break;}for(int i = 0; i < count ;i++){buf[index+i] = tmp[i];}index+=count;}return Math.min(index,n);}
}