Here you can find the source of readBinaryFile(File file)
static public ByteBuffer readBinaryFile(File file) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.ByteBuffer; public class Main { static public ByteBuffer readBinaryFile(File file) throws IOException { ByteBuffer result = ByteBuffer.allocate((int) file.length()); BufferedInputStream in = new BufferedInputStream(new FileInputStream(file)); byte[] buf = new byte[1024]; int len = 0; while ((len = in.read(buf)) != -1) { result.put(buf, 0, len);/*from w w w. j av a 2 s .c o m*/ } in.close(); result.flip(); return result; } }