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();
    }
}

你可能感兴趣的:(JAVA基础,java,python,开发语言)