feat(新增): 📌 rewind方法

This commit is contained in:
bunny 2024-05-22 16:57:39 +08:00
parent caf69c6707
commit 5df9a0d8d0
3 changed files with 28 additions and 0 deletions

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GitCommitMessageStorage">
<option name="messageStorage">
<MessageStorage />
</option>
</component>
</project>

View File

@ -0,0 +1,20 @@
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
}
}

Binary file not shown.