Java tutorial
import java.nio.ByteBuffer; public class Main { public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(8); printBufferInfo(bb); for (int i = 50; i < 58; i++) { bb.put((byte) i); } printBufferInfo(bb); } public static void printBufferInfo(ByteBuffer bb) { int limit = bb.limit(); System.out.println("Position = " + bb.position() + ", Limit = " + limit); for (int i = 0; i < limit; i++) { System.out.print(bb.get(i) + " "); } System.out.println(); } }