package cn.bunny.file_dir;

import java.nio.ByteBuffer;

public class Demo4 {

    public static void main(String[] args) {
        ByteBuffer buffer = ByteBuffer.allocate(10);
        buffer.put(new byte[]{'a', 'b', 'c', 'd', 'e'});

        // rewind 重头开始读
        buffer.get(new byte[4]);
        // 重新读取
        buffer.rewind();
        System.out.println((char) buffer.get());// a

        // mark & reset
        System.out.println((char) buffer.get());// b
        System.out.println((char) buffer.get());// c

        // get(i) 不会改变读索引
        System.out.println((char) buffer.get());
    }
}
