赞
踩
放入什么类型,取出就要用什么类型,顺序要一致。否则会报 BufferUnderflowException
public static void main(String[] args) {
ByteBuffer buffer = ByteBuffer.allocate(1024);
buffer.putInt(100);
buffer.putLong(100L);
buffer.putChar('陈');
buffer.putShort((short) 4);
//调用buffer.flip() 切换到读模式
buffer.flip();
System.out.println(buffer.getInt());
System.out.println(buffer.getLong());
System.out.println(buffer.getChar());
System.out.println(buffer.getShort());
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。