读书人

从ByteBuffer中获取基本门类

发布时间: 2012-12-18 12:43:41 作者: rapoo

从ByteBuffer中获取基本类型
我们可以从ByteBuffer中产生出不同类型值的方法

public class Test{       public static final int BSIZE=1024;       public static void main(){            ByteBuffer bb=ByteBuffer.allocate(BSIZE);            int i=0;            while(i++<bb.limit())       if(bb.get()!=0)                   System.out.print("nozero");               System.out.println("i ="+i);               bb.rewind();               bb.asShortBuffer().put((short)471142);               System.out.print(bb.getShort());               bb.rewind();               bb.asIntBuffer().put(9947142);               System.out.print(bb.getInt());               bb.rewind();               bb.asLongBuffer().put(99471142);               System.out.print(bb.getLong());               bb.rewind();               bb.asFloatBuffer().put(99471142);               System.out.print(bb.getFloat());               bb.rewind();               bb.asDoubleBuffer().put(99471142);               System.out.print(bb.getDouble());               bb.rewind();                                              }}

读书人网 >编程

热点推荐