Here you can find the source of readFileToByte(File file)
public static byte[] readFileToByte(File file) throws IOException
//package com.java2s; import java.io.*; public class Main { public static byte[] readFileToByte(File file) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream( (int) file.length()); BufferedInputStream in = null; try {//from w ww . j ava 2 s . c o m in = new BufferedInputStream(new FileInputStream(file)); int buf_size = 1024; byte[] buffer = new byte[buf_size]; int len = 0; while (-1 != (len = in.read(buffer, 0, buf_size))) { bos.write(buffer, 0, len); } return bos.toByteArray(); } finally { if (in != null) { try { in.close(); } catch (IOException e) { e.printStackTrace(); } } if (bos != null) { bos.close(); } } } }