How can I use ReadableByteChannel to get file contents and store it in byteBuffer?
<p>Below is the code that I have written. I want to do the simple thing, storing binary file data into byteBuffer. </p>

<pre><code>File file = new File(fileName);
try {
    ReadableByteChannel channel = new FileInputStream(fileName).getChannel();
    ByteBuffer buf = ByteBuffer.allocateDirect(file.length());

    // How can use buf.read to get all the contents?

} catch (Exception e){

}
</code></pre>

<p>I was wondering </p>

<ol>
<li>how can I use <code>read</code> to get all data from channel and store it in ByteBuffer</li>
<li>if there is more elegant way to allocate <code>ByteBuffer</code>, other than using <code>File</code> object to get the length of the file</li>
</ol>
