Here you can find the source of readFile(String path, long offset)
public static byte[] readFile(String path, long offset) throws IOException
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] readFile(String path) throws IOException { return readFile(path, 0); }/*from ww w. ja v a2 s. c om*/ public static byte[] readFile(String path, long offset) throws IOException { return readFile(path, offset, -1); } public static byte[] readFile(String path, long offset, int size) throws IOException { InputStream is = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); is = new FileInputStream(path); is.skip(offset); byte[] buff = new byte[4096]; int bufLength = -1; while ((bufLength = is.read(buff)) >= 0) { if (size > 0 && bufLength > size - baos.size()) { baos.write(buff, 0, size - baos.size()); break; } else { baos.write(buff, 0, bufLength); } } return baos.toByteArray(); } finally { if (is != null) { is.close(); } } } }