Here you can find the source of readByteBufferFromFile(String filepath)
public static ByteBuffer readByteBufferFromFile(String filepath) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class Main { public static ByteBuffer readByteBufferFromFile(String filepath) throws IOException { File file = new File(filepath); FileChannel inChannel;/*ww w . j a va2 s.c o m*/ inChannel = new FileInputStream(file).getChannel(); ByteBuffer buf = ByteBuffer.allocate((int) file.length()); inChannel.read(buf); inChannel.close(); buf.rewind(); return buf; } }