Here you can find the source of readFile(File path)
private static byte[] readFile(File path) throws FileNotFoundException, IOException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; public class Main { private static byte[] readFile(File path) throws FileNotFoundException, IOException { int length = (int) path.length(); byte[] content = new byte[length]; InputStream inStream = new FileInputStream(path); try {//from w ww .j a va 2 s . c om inStream.read(content); } finally { inStream.close(); } return content; } private static byte[] read(InputStream input) throws IOException { ByteArrayOutputStream output = new ByteArrayOutputStream(); try { byte[] buffer = new byte[1024]; int nBytes = 0; while ((nBytes = input.read(buffer)) > 0) { output.write(buffer, 0, nBytes); } byte[] result = output.toByteArray(); return result; } finally { try { input.close(); } catch (IOException e) { } } } }