feat(新增): 📌 rewind方法
This commit is contained in:
parent
caf69c6707
commit
5df9a0d8d0
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GitCommitMessageStorage">
|
||||
<option name="messageStorage">
|
||||
<MessageStorage />
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
|
@ -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.
Loading…
Reference in New Issue