How to use a FileChannel to read data into a Buffer?
The example below show how to use a
FileChannel to read some data into a Buffer. We create a
FileChannel from a
FileInputStream instance. Because a channel reads data into buffer we need to create a
ByteBuffer and set its capacity. Read data from a channel into buffer using the
To read out the data from the buffer we need to flip the buffer first using the
Buffer.flip() method. The method will change the buffer from writing-mode into reading-mode. After the entire buffer is read clear the buffer using the
clear() method call.