package cn.bunny.file_dir;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;

public class Demo6 {

    public static void main(String[] args) {
        ByteBuffer b1Buffer = StandardCharsets.UTF_8.encode("hello");
        ByteBuffer b2Buffer = StandardCharsets.UTF_8.encode("world");
        ByteBuffer b3Buffer = StandardCharsets.UTF_8.encode("你好");

        try (FileChannel channel = new RandomAccessFile("data.txt", "rw").getChannel()) {
            channel.write(new ByteBuffer[]{b1Buffer, b2Buffer, b3Buffer});

        } catch (IOException exception) {

        }
    }
}
