0
点赞
收藏
分享

微信扫一扫

java: MappedByteBuffer的用法


package nio;

import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;

public class MappedByteBufferTest {
    public static void main(String[] args) throws Exception{
        RandomAccessFile randomAccessFile = new RandomAccessFile("d:\\1122.txt", "rw");
        FileChannel fileChannel = randomAccessFile.getChannel();
        MappedByteBuffer buffer = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, 10);
        for(int i = 0; i < 10; i ++){
            buffer.put(i, (byte)(65 + i));
        }
        fileChannel.close();
    }
}


举报

相关推荐

0 条评论