Here you can find the source of read(Path file, int pos, int length)
public static MappedByteBuffer read(Path file, int pos, int length) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.MappedByteBuffer; import java.nio.channels.FileChannel; import java.nio.file.Path; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; public class Main { private static Map<String, FileChannel> FILES = new ConcurrentHashMap<String, FileChannel>(); public static MappedByteBuffer read(Path file, int pos, int length) throws IOException { return getFileChannel(file, "r").map(FileChannel.MapMode.READ_ONLY, pos, length); }// w w w . j a va2s . co m public static FileChannel getFileChannel(Path file, String mode) throws FileNotFoundException { if (!FILES.containsKey(file.toString())) { FILES.put(file.toString(), new RandomAccessFile(file.toString(), mode).getChannel()); } return FILES.get(file.toString()); } }