Buffer class provides ‘position’ method to get the
current position of the buffer.
package com.sample.nio; import java.nio.ByteBuffer; public class Test { public static void main(String args[]) throws Exception { ByteBuffer byteBuffer = ByteBuffer.allocate(10); System.out.println("Current position of the buffer " + byteBuffer.position()); System.out.println("Adding two elements to the buffer"); byteBuffer.put((byte) 'H'); byteBuffer.put((byte) 'I'); System.out.println("Current position of the buffer " + byteBuffer.position()); } }
Output
Current position of the buffer 0
Adding two elements to the buffer
Current position of the buffer 2
No comments:
Post a Comment