Here you can find the source of readFile(File file)
public static byte[] readFile(File file)
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Main { public static byte[] readFile(File file) { try {/* ww w.jav a 2 s . c om*/ if (file.length() > 1 << 30) { throw new ArrayIndexOutOfBoundsException("File is too big"); } byte[] data = new byte[(int) file.length()]; FileInputStream fis = new FileInputStream(file); try { int n = 0; while (n < data.length) { int m = fis.read(data, n, data.length - n); if (m < 0) { throw new RuntimeException("Cannot read file: " + file.getCanonicalPath()); } n += m; } } finally { try { fis.close(); } catch (IOException e) { // ignore } } return data; } catch (IOException e) { throw new RuntimeException(e); } } }