Here you can find the source of readFile(File f)
public static final byte[] readFile(File f) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; public class Main { public static final byte[] readFile(File f) throws IOException { int len = f.length() > Integer.MAX_VALUE ? 8192 : (int) f.length(); byte[] buf = new byte[len]; FileInputStream is = new FileInputStream(f); try {// w ww. ja v a2 s .c o m ByteArrayOutputStream os = new ByteArrayOutputStream((int) f.length()); int n = is.read(buf); while (n != -1) { os.write(buf, 0, n); n = is.read(buf); } return os.toByteArray(); } finally { is.close(); } } }