断点续传里用到的一个重要方法就是inputstream的skip方法,但是在使用的时候有一点需要注意,就是skip不能保证你的输入流准确的跳过count个字节。
看看这个方法的介绍是怎么说的
Skips at most {@code byteCount} bytes in this stream. The number of actual * bytes skipped may be anywhere between 0 and {@code byteCount}.
Note the "at most" in the description of this method: this method may * choose to skip fewer bytes than requested. Callers should <i>always</i> * check the return value.
所以单纯的只是 in.skip(count)是不行的,改成
int skip = (int) in.skip(m_currentBlockPos);
while(skip<m_currentBlockPos){
m_currentBlockPos-=skip;
skip = (int) in.skip(m_currentBlockPos);
}
解决问题!