FileInputStream read(byte b[])源码解析

问题描述

源文件source.txt中有10个字节(GBK编码)的数据 qwertyuiop ,当使用4字节的byte数组读取时,依次读取出qwer tyui opui,造成数据重复,如图
在这里插入图片描述

源码解析

查看源码发现实际调用的是readBytes(byte b[], int off, int len) 方法,此方法是native,无法看到具体实现,但是其继承的InputStream有如下方法可供参考

/**     
* @param      b     the buffer into which the data is read.
* @param      off   the start offset in array <code>b</code>
*                   at which the data is written.
* @param      len   the maximum number of bytes to read.
*@ return the total number of bytes read into the buffer, or
*			  <code>-1</code> if there is no more data because the end of
*             the stream has been reached
* 			 
*/
    public int read(byte b[], int off, 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值