Java ByteBuffer store long type data via LongBuffer and read

Description

Java ByteBuffer store long type data via LongBuffer and read


import java.nio.ByteBuffer;

public class Main {
   private static final int BSIZE = 1024;

   public static void main(String[] args) {
      ByteBuffer bb = ByteBuffer.allocate(BSIZE);

      bb.rewind();//from w  w w  . ja  v a2s  .  c  o  m
      // Store and read a long:
      bb.asLongBuffer().put(999999999999L);
      System.out.println(bb.getLong());

   }
}



PreviousNext

Related