netty/demo1/src/main/java/cn/bunny/Demo4.java

21 lines
533 B
Java
Raw Normal View History

2024-05-22 16:57:39 +08:00
package cn.bunny;
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
}
}