Here you can find the source of readBytes(File file)
public static final byte[] readBytes(File file) throws IOException
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; public class Main { public static final byte[] readBytes(InputStream in) throws IOException { byte[] ret = new byte[0]; byte[] buf = new byte[2048]; int len;//from w w w .j ava 2 s. c om for (;;) { len = in.read(buf); if (len > 0) { ret = Arrays.copyOf(ret, ret.length + len); System.arraycopy(buf, 0, ret, ret.length - len, len); } else { break; } } return ret; } public static final byte[] readBytes(String path) throws IOException { return readBytes(new File(path)); } public static final byte[] readBytes(File file) throws IOException { FileInputStream in = new FileInputStream(file.getAbsolutePath()); try { return readBytes(in); } catch (IOException e) { throw e; } finally { in.close(); } } }