Mega Code Archive

 
Categories / Java Tutorial / File
 

Use while loop to read a ByteBuffer

import java.nio.ByteBuffer; 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();     System.out.println("Byte Buffer");     while (bb.hasRemaining())       System.out.println(bb.position() + " -> " + bb.get());   } } /**/ Byte Buffer 0 - 0 1 - 0 2 - 0 3 - 0 4 - 0 5 - 0 6 - 0 7 - 97