Java如何创建NIO缓冲区?
这篇文章告诉你如何使用java.nio缓冲区如ByteBuffer,CharBuffer,DoubleBuffer等创建缓冲区,可以使用allocate(int capacity)方法。每个缓冲区对象都有allocate(int capacity)方法。调用此方法时,您需要传递要创建的缓冲区的容量值。
package org.nhooo.example.nio;import java.nio.*;
public class BufferAllocate {
public static void main(String[] args) {
ByteBuffer byteBuffer = ByteBuffer.allocate(64);
CharBuffer charBuffer = CharBuffer.allocate(64);
ShortBuffer shortBuffer = ShortBuffer.allocate(64);
IntBuffer intBuffer = IntBuffer.allocate(64);
LongBuffer longBuffer = LongBuffer.allocate(64);
FloatBuffer floatBuffer = FloatBuffer.allocate(64);
DoubleBuffer doubleBuffer = DoubleBuffer.allocate(64);
}
}
以上是 Java如何创建NIO缓冲区? 的全部内容, 来源链接: utcz.com/z/321410.html