read函數,返回-1
例子:三個字節(1,2,3)的文件,每次讀兩個字節,第三次才會返回-1,
第一次讀取到的是 (1,2),read返回 len = 2;
第二次讀取到的是(3,2), read返回 len = 1;
第三次讀取到的是(3,2), read返回 len = -1;
read源碼:
public int read(byte[] b) throws IOException {
int getData = read();
if (getData==-1) {
return -1;
}else{
b[0] = (byte)getData;
for (int i = 1; i < b.length; i++) {
getData = read();
if(-1==getData)
return i;
b[i] = (byte)getData;
}
}
return b.length;
}
