Java ByteBuffer store int type value via IntBuffer and read

Description

Java ByteBuffer store int type value via IntBuffer 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();// w ww.  ja v  a 2s.  c o m
      // Store and read an int:
      bb.asIntBuffer().put(1234567);
      System.out.println(bb.getInt());

   }
}



PreviousNext

Related