使用NIO的FileChannel和ByteBuffer高效读取文件
来源:互联网 发布:linux中echo 编辑:程序博客网 时间:2024/06/07 01:28
http://hi.baidu.com/boywell/blog/item/658d143f730a553770cf6ccd.html
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
public class ReadWriteCompare
{
public static void main(String[] args) throws IOException
{
FileInputStream fileInputStream = new FileInputStream("f:"+ File.separator +"IBM e-Mentor Program Kickoff Night 1105.pdf");
FileOutputStream fileOutputStream = new FileOutputStream("f:" + File.separator + "test.pdf");
FileChannel inChannel = fileInputStream.getChannel();
FileChannel outChannel= fileOutputStream.getChannel();
ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
//Direct Buffer的效率会更高。
// ByteBuffer byteBuffer = ByteBuffer.allocateDirect(1024);
long start = System.currentTimeMillis();
while(true)
{
int eof = inChannel.read(byteBuffer);
if(eof == -1 ) break;
byteBuffer.flip();
outChannel.write(byteBuffer);
byteBuffer.clear();
}
System.out.println("spending : " + (System.currentTimeMillis()-start));
inChannel.close();
outChannel.close();
}
}
- 使用NIO的FileChannel和ByteBuffer高效读取文件
- Java NIO ByteBuffer读取文件
- 使用FileChannel读取文件
- 【NIO】通过FileChannel读取包含中文内容的文件
- FileChannel 与 ByteBuffer 操作文件
- Java NIO 学习 ByteBuffer,FileChannel,Socket
- FileChannel类的理解和使用(java.nio.channels.FileChannel)
- FileChannel、ByteBuffer对文件操作过程对比
- (Mina的ByteBuffer和java.nio.ByteBuffer性能对比)Performance comparision of Mina's ByteBuffer VS java.nio.ByteBuffer use.
- java.nio.ByteBuffer的flip、rewind和compact几个方法的区分使用 (转载)
- java.nio.ByteBuffer的flip、rewind和compact几个方法的区分使用
- ByteBuffer读取文件乱码
- 使用filechannel高效拷贝数据
- JAVA中IO和NIO的详解分析,FileChannel
- nio.FileChannel 、io.Stream 和 io.buffer速度的比较
- Java的NIO之FileChannel
- byteBuffer的理解和使用
- 【Java】NIO ByteBuffer类使用
- (一)IBM FileNet 平台概览
- Ios 消息处理
- Junit使用基础总结
- ORACLE 临时表 .
- WIFI连接原理
- 使用NIO的FileChannel和ByteBuffer高效读取文件
- shell脚本调试
- Java NIO 小结
- C#密闭类
- SQL 临时表
- 03_HL7简介
- Oracle存储过程语法 .
- .Net下的加密解密大全(5):玩转对称加密
- 视讯音频标准推陈出新,谁是音频效果之霸?