java读文件块会读出null,为什么?

来源:互联网 发布:远控软件下载 编辑:程序博客网 时间:2024/06/05 17:21

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;}


0 0
原创粉丝点击