java读文件块会读出null,为什么?
可以确定这个块不是最后一块
/**
* 从文件中读取一块数据
* @param fs
* @param seel:第几块
* @param vChunkSize:块大小
* @return
*/
public static byte[] readChunkData(FileInputStream fs, int seel, int vChunkSize) {
String tag = "readChunkData";
long t0 = System.currentTimeMillis();
Log.i(tag, "1, seel="+seel+", vChunkSize="+vChunkSize);
if(vChunkSize < 1){
return null;
}
ByteArrayOutputStream bos = null;
byte[] chunkData = null;
try {
bos = new ByteArrayOutputStream();
byte[] tempdata = new byte[vChunkSize];
int len = 0;
int curTotal = 0;
fs.skip(seel*vChunkSize);
while ((len = fs.read(tempdata)) != -1) {
curTotal += len;
bos.write(tempdata, 0, len);
if (curTotal >= vChunkSize) {
break;
}
}
chunkData = bos.toByteArray();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != bos) {
try {
bos.close();
} catch (IOException e) {
e.printStackTrace();
} finally {
bos = null;
}
}
}
long t = System.currentTimeMillis() - t0;
Log.i(tag, " 用时 = "+ t);
return chunkData;
}