速度的提高由于:通道和缓冲区。
唯一与通道交互的缓冲器:ByteBuffer
怎么定义通道:FileChannel fc=new FileOutputStream(“data.txt”).getChannel();
复制文件:
FileChannel in=new FileInputStream(“data.txt”).getChannel();
FileChannel out=new FileOutputStream(“data.txt”).getChannel();
in.transferTo(0,in.size(),out)/out.transferFrom(in,0,in.size());
ByteBuffer存取基本数据类型,ByteBuffer bb=ByteBuffer.allocate(1024);
存:bb.as1Buffer().put(2),1是基本数据类型的类型名,2是值
取:bb.get类型名();
ByteBuffer以高位优先形式存储数据。
内存映射文件:
MapedByteBuffer out=new RandomAccessFile(“data.txt”,”rw”).getChannel().map(FileChannel.MapModel.READ_WRITE,0,length);
唯一与通道交互的缓冲器:ByteBuffer
怎么定义通道:FileChannel fc=new FileOutputStream(“data.txt”).getChannel();
复制文件:
FileChannel in=new FileInputStream(“data.txt”).getChannel();
FileChannel out=new FileOutputStream(“data.txt”).getChannel();
in.transferTo(0,in.size(),out)/out.transferFrom(in,0,in.size());
ByteBuffer存取基本数据类型,ByteBuffer bb=ByteBuffer.allocate(1024);
存:bb.as1Buffer().put(2),1是基本数据类型的类型名,2是值
取:bb.get类型名();
ByteBuffer以高位优先形式存储数据。
内存映射文件:
MapedByteBuffer out=new RandomAccessFile(“data.txt”,”rw”).getChannel().map(FileChannel.MapModel.READ_WRITE,0,length);