Here you can find the source of readToByteBuffer(File f)
public static ByteBuffer readToByteBuffer(File f) throws IOException
//package com.java2s; //License from project: Open Source 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 readToByteBuffer(File f) throws IOException { return readToByteBuffer(f, (int) f.length()); }/* www . j a va2 s.c om*/ public static ByteBuffer readToByteBuffer(File f, int toRead) throws IOException { ByteBuffer b = ByteBuffer.allocate(toRead); FileChannel fc = new FileInputStream(f).getChannel(); fc.read(b); fc.close(); b.flip(); return b; } }