Mega Code Archive

 
Categories / Java Tutorial / File
 

Use while loop to read an IntBuffer

import java.nio.ByteBuffer; import java.nio.IntBuffer; public class MainClass {   public static void main(String[] args) {     ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, 'a' });     bb.rewind();     IntBuffer ib = ((ByteBuffer) bb.rewind()).asIntBuffer();     System.out.println("Int Buffer");     while (ib.hasRemaining())       System.out.println(ib.position() + " -> " + ib.get());   } } /*  */ Int Buffer 0 - 0 1 - 97