Here you can find the source of readEntireFile(java.io.File file)
public static java.nio.ByteBuffer readEntireFile(java.io.File file) throws java.io.IOException
//package com.java2s; import java.io.*; import java.nio.channels.FileChannel; public class Main { public static java.nio.ByteBuffer readEntireFile(java.io.File file) throws java.io.IOException { return readFileToBuffer(file); // return memoryMapFile(file); // return readFile(file); }/*from ww w . jav a 2 s . c o m*/ private static java.nio.ByteBuffer readFileToBuffer(java.io.File file) throws IOException { FileInputStream is = new FileInputStream(file); try { FileChannel fc = is.getChannel(); java.nio.ByteBuffer buffer = java.nio.ByteBuffer .allocate((int) fc.size()); for (int count = 0; count >= 0 && buffer.hasRemaining();) { count = fc.read(buffer); } buffer.flip(); return buffer; } finally { is.close(); } } }