字节流read方法返回值为什么是int不是byte

01001000 01001000 01001000 11111111 01001000 

-1的原码:

  10000001 

-1的反码:

  11111110

-1的补码:

  11111111

所以如果返回值用byte接收的话,01001000 01001000 01001000 11111111 01001000 在11111111时就会停止

因为read方法读取数据结束标志就是返回值是-1

while((b=fis.read())!=-1){

}

 

posted @ 2018-08-16 10:33  *青锋*  阅读(607)  评论(0编辑  收藏  举报