e158. creating a bytebuffer.txt
来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 18 行
TXT
18 行
A ByteBuffer is a fixed-capacity buffer that holds byte values. This example demonstrates a number of ways to create a ByteBuffer.
See also e159 Getting Bytes from a ByteBuffer and e160 Putting Bytes into a ByteBuffer.
// Create a ByteBuffer using a byte array
byte[] bytes = new byte[10];
ByteBuffer buf = ByteBuffer.wrap(bytes);
// Create a non-direct ByteBuffer with a 10 byte capacity
// The underlying storage is a byte array.
buf = ByteBuffer.allocate(10);
// Create a direct (memory-mapped) ByteBuffer with a 10 byte capacity.
buf = ByteBuffer.allocateDirect(10);
// To create a ByteBuffer for a memory-mapped file,
// see e166 Creating a Memory-Mapped File
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?