Here you can find the source of readFileFragment(FileChannel fc, long pos, int size)
public static ByteBuffer readFileFragment(FileChannel fc, long pos, int size)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class Main { public static ByteBuffer readFileFragment(FileChannel fc, long pos, int size) { ByteBuffer fragment = null; try {/*w w w. jav a 2 s. c o m*/ fc.position(pos); fragment = ByteBuffer.allocate(size); if (fc.read(fragment) != size) return null; fragment.rewind(); } catch (IOException ex) { ex.printStackTrace(); return null; } return fragment; } }