Here you can find the source of readFromFile(String fileName)
public final static ByteBuffer readFromFile(String fileName) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.FileChannel.MapMode; public class Main { public final static ByteBuffer readFromFile(String fileName) throws IOException { RandomAccessFile fis = null; MappedByteBuffer buf = null; try {//from ww w .ja v a 2 s. c o m fis = new RandomAccessFile(fileName, "r"); final FileChannel fc = fis.getChannel(); int size = (int) fc.size(); buf = fc.map(MapMode.READ_ONLY, 0, size); return buf; } finally { fis.close(); // closeDirectBuffer(buf); } } }