问题描述
源文件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,