对字节流操作时,如果自己封装read()方法的话,如果需要返回一个int型的话,那么要在返回前让待返回的byte型和0xff做一个与运算,这样能保证在byte(8位)转换成int(32位)的时候,自动添加的24位为全0。
/**
* Read byte.
*/
public int read()
throws IOException {
if (pos >= count) {
fill();
if (pos >= count)
return -1;
}
return buf[pos++] & 0xff;
}