Source Code : How to get bytes from a ByteBuffer

Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com. Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com. Click Here or search from google with Libraries Name you get jar file related it

How to get bytes from a ByteBuffer

 

public class Main{
public static void main(String[] argv) throws Exception{
    // Create an empty ByteBuffer with a 10 byte capacity
    ByteBuffer bbuf = ByteBuffer.allocate(10);
    
    // Retrieve the capacity of the ByteBuffer
    int capacity = bbuf.capacity(); // 10
    
    // The position is not affected by the absolute get() method.
    byte b = bbuf.get(5); // position=0
    
    // Set the position
    bbuf.position(5);
    
    // Use the relative get()
    b = bbuf.get();
    
    // Get the new position
    int pos = bbuf.position(); 
    
    // Get remaining byte count
    int rem = bbuf.remaining();
    
    // Set the limit
    bbuf.limit(7); // remaining=1
    
    // This convenience method sets the position to 0
    bbuf.rewind(); // remaining=7
    
}}    

   
  

Thank with us