在ByteBuffer上创建非字节Java类型缓冲区
import java.nio.ByteBuffer; import java.nio.CharBuffer; /** from * 时 代 J a v a 公 众 号 - nowjava.com **/ import java.nio.DoubleBuffer; import java.nio.FloatBuffer; import java.nio.IntBuffer; import java.nio.LongBuffer; import java.nio.ShortBuffer; public class Main { public void myMethod() { // Obtain a ByteBuffer; see also Creating a ByteBuffer ByteBuffer buf = ByteBuffer.allocate(15); // remaining = 15 // Create a character ByteBuffer CharBuffer cbuf = buf.asCharBuffer(); // remaining = 7 // Create a short ByteBuffer /** 来 自 n o w j a v a . c o m - 时代Java **/ ShortBuffer sbuf = buf.asShortBuffer(); // remaining = 7 // Create an integer ByteBuffer IntBuffer ibuf = buf.asIntBuffer(); // remaining = 3 // Create a long ByteBuffer LongBuffer lbuf = buf.asLongBuffer(); // remaining = 1