Here you can find the source of readFile(String path)
public static byte[] readFile(String path) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.InputStream; public class Main { public static byte[] readFile(String path) throws Exception { return readStream(new FileInputStream(path)); }/*from w w w . j a va 2s . c o m*/ public static byte[] readStream(InputStream inStream) throws Exception { byte[] buffer = new byte[1024]; int len = -1; ByteArrayOutputStream outStream = new ByteArrayOutputStream(); while ((len = inStream.read(buffer)) != -1) { outStream.write(buffer, 0, len); } outStream.flush(); byte[] data = outStream.toByteArray(); outStream.close(); inStream.close(); return data; } }