Here you can find the source of readFile(String file)
public static byte[] readFile(String file) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.FileInputStream; import java.io.IOException; public class Main { public static byte[] readFile(String file) throws IOException { FileInputStream fis = new FileInputStream(file); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buff = new byte[1024]; int read; while ((read = fis.read(buff)) != -1) { baos.write(buff, 0, read);/*from w ww . j ava 2 s.c om*/ } baos.flush(); fis.close(); byte[] dat = baos.toByteArray(); baos.close(); return dat; } }