ByteBuffer读大文件以及组装
来源:互联网 发布:狼图腾知乎 编辑:程序博客网 时间:2024/06/08 00:33
public String mappedBuffer(String file) throws IOException{ FileChannel read = new FileInputStream(file).getChannel(); long i = 0; long size = read.size()/30; ByteBuffer bb = null; ByteBuffer temp = null, all = null; while(i<read.size()&&(read.size()-i)>size){ bb = ByteBuffer.allocate((int)size); bb = bb.put(read.map(FileChannel.MapMode.READ_ONLY, i, size)); if (all!=null){ temp = ByteBuffer.allocate(all.limit()); temp = temp.put(all.array()); } if (all==null){ all = ByteBuffer.allocate(bb.limit()); }else{ all = ByteBuffer.allocate(temp.limit()+bb.limit()); } all.clear(); if (temp!=null){ all = all.put(temp.array()); } all = all.put(bb.array()); i+=size; bb.clear(); if (temp!=null){ temp.clear(); } } bb = ByteBuffer.allocate((int)(read.size()-i)); bb = bb.put(read.map(FileChannel.MapMode.READ_ONLY, i, read.size()-i)); if (all!=null){ temp = ByteBuffer.allocate(all.limit()); temp = temp.put(all.array()); } if (all==null){ all = ByteBuffer.allocate(bb.limit()); }else{ all = ByteBuffer.allocate(temp.limit()+bb.limit()); } all.clear(); if (temp!=null){ all = all.put(temp.array()); } all = all.put(bb.array()); all.flip(); Charset charset=Charset.forName("GBK"); String bufData = charset.decode(all).toString(); //System.out.println("====bufData="+bufData); bb.clear(); if (temp!=null){ temp.clear(); } read.close(); return bufData; }
0 0
- ByteBuffer读大文件以及组装
- Java 用 ByteBuffer和RandomAccessFile 写大文件
- 使用通道和byteBuffer进行大文件分批传输
- ByteBuffer读取文件乱码
- 学习笔记之ByteBuffer使用和实现以及文件内存映射
- Java NIO ByteBuffer读取文件
- FileChannel 与 ByteBuffer 操作文件
- ByteBuffer
- ByteBuffer
- ByteBuffer
- ByteBuffer
- ByteBuffer
- ByteBuffer
- ByteBuffer
- ByteBuffer
- linux如何查找大文件以及大文件夹
- RandomAccessFile-文件分割和组装
- FileChannel、ByteBuffer对文件操作过程对比
- 设计模式之调停者模式
- Android创建一个选项菜单
- sql语句获取本周、上一周、本月数据
- 英雄联盟-经验砖块
- filter函数(JS)
- ByteBuffer读大文件以及组装
- 三星刷完机后一直停留在Samsung页面
- caffe中几个基本概念
- tomcat中部署多个项目时遇到问题
- Ubuntu中python调用SimpleITK来显示图像
- How should you start learn Madwifi
- parseInt()和parseFloat()
- 【每天一个Linux命令】A-alias
- 企业需要什么样的产品经理?