1 /** 2 * The read4 API is defined in the parent class Reader4. 3 * int read4(char[] buf4); 4 */ 5 6 public class Solution extends Reader4 { 7 /** 8 * @param buf Destination buffer 9 * @param n Number of characters to read 10 * @return The number of actual characters read 11 */ 12 public int read(char[] buf, int n) { 13 int ans = 0; 14 char[] buf4 = new char[4];//目标缓存区 15 int size = read4(buf4); 16 while(size>0&&ans<n){ 17 //size>0指的是文件还有剩余的字符 18 //ans<n意思就是目前的长度不超过n 19 for(int i=0;i<size&&ans<n;++i){ 20 buf[ans++] = buf4[i]; 21 } 22 size = read4(buf4); 23 } 24 return ans; 25 } 26 }
标签:ac,java,157,int,buf4,char,read,read4 From: https://www.cnblogs.com/h404nofound/p/16770609.html