1、分散读取:将通道中的数据分散到多个缓冲区中(按照缓冲区的顺序,从 Channel 中读取的数据依次将 Buffer 填满。
),
聚集写入:将多个缓冲区中数据聚集到通道中(按照缓冲区的顺序,写入 position 和 limit 之间的数据到 Channel
),
2、FileChannel 的常用方法
方 法 | 描 述 |
int read(ByteBuffer dst) | 从 Channel 中读取数据到 ByteBuffer |
long read(ByteBuffer[] dsts) | 将 Channel 中的数据“分散”到 ByteBuffer[] |
int write(ByteBuffer src) | 将 ByteBuffer 中的数据写入到 Channel |
long write(ByteBuffer[] srcs) | 将 ByteBuffer[] 中的数据“聚集”到 Channel |
long position() | 返回此通道的文件位置 |
FileChannel position(long p) | 设置此通道的文件位置 |
long size() | 返回此通道的文件的当前大小 |
FileChannel truncate(long s) | 将此通道的文件截取为给定大小 |
void force(boolean metaData) | 强制将所有对此通道的文件更新写入到存储设备中 |