62,621
社区成员
发帖
与我相关
我的任务
分享 public int read() throws IOException {
synchronized (lock) {
ensureOpen();//查看连接是否掉了
for (;;) {
if (nextChar >= nChars) {//缓存里的字符是读取完
fill();//清楚缓存数据重新读一批到缓存
if (nextChar >= nChars)//新的缓存数据是滞读取完
return -1;//刚读进缓存数据也读取完的话证明数据已读完
}
if (skipLF) {
skipLF = false;
if (cb[nextChar] == '\n') {//回车的话过
nextChar++;
continue;
}
}
return cb[nextChar++]; //返回下一个数据
}
}
} do {
//dst=0表示cb[]字段全部更新,dst>0表示标记字符串的长度.
n = in.read(cb, dst, cb.length - dst);
} while (n == 0);
防止读取不到数据,如果读取完成果断-1 如果没完成是0的话可能跳过字符过多(各种差错)