In this tutorial, we will discuss how to get bytes from buffer.
The ByteBuffer class is a container for handling data. The
method allocate( int capacity) creates a new byte buffer, and
the current position will be zero and its limit will be it's
capacity. The FileChannel class creates a channel for reading,
writing, mapping and manipulating a file. The FileChannel is
similar to the stream but they are few different. The channel
can read write bot, but stream can either read-only or write-
only. The getChannel method of FileInputStream class returns the
Channel object associated with this file input stream. The
read() method of FileChannel class fills byte buffer created by
using allocate() method. The get() method of ByteBuffer class
reads bytes of from buffer's current position and increment
position. About ByteBuffer API: The java.nio.ByteBuffer class
extends java.nio.Buffer class. It provides the following
methods: |static ByteBuffer||allocate( int capacity)||The
allocate() method create a byte buffer of sp