Here you can find the source of getBytesFromFile(String filename)
public static byte[] getBytesFromFile(String filename) throws IOException
//package com.java2s; //License from project: Apache License import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; public class Main { public static byte[] getBytesFromFile(String filename) throws IOException { File f = new File(filename); if (!f.exists()) { throw new FileNotFoundException(filename); }//from w ww.j a v a2s . co m ByteArrayOutputStream bos = new ByteArrayOutputStream((int) f.length()); BufferedInputStream in = null; try { in = new BufferedInputStream(new FileInputStream(f)); 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 { try { in.close(); } catch (IOException e) { e.printStackTrace(); } bos.close(); } } }