功能描述
将文件分割成几块,利用多线程同时写入。
利用 RandomAccessFile 访问文件部分内容
利用 FileChannel 对线程独占的文件快需要加锁
利用 MappedByteBuffer 对文件进行并发写入
(1)RandomAccessFile
访问文件的部分内容
RandomAccessFile的第一个参数 mod,主要用来指定打开文件的访问模式。
(2)java.nio.channels.FileChannel
Acquires a lock on the given region of this channel's file
获取此通道文件的给定区域上的锁
(3)MappedByteBuffer
FileChannel提供了map方法来把文件映射为MappedByteBuffer: MappedByteBuffer map(int mode,long position,long size); 可以把文件的从position开始的size大小的区域映射为MappedByteBuffer
具体内容请参考:
https://blog.csdn.net/nmgrd/article/details/81335439
RandomAccessFile 请参考:
https://www.cnblogs.com/dongguacai/p/5699444.html
MappedByteBuffer 请参考:
http://langgufu.iteye.com/blog/2107023