Here you can find the source of dumpFileIntoByteArray(File f)
public static byte[] dumpFileIntoByteArray(File f) 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.IOException; public class Main { public static byte[] dumpFileIntoByteArray(File f) throws IOException { ByteArrayOutputStream byteStream = null; BufferedInputStream fileStream = null; try {/*from w ww.j a v a 2 s .c o m*/ byteStream = new ByteArrayOutputStream(); fileStream = new BufferedInputStream(new FileInputStream(f)); int data = -1; while ((data = fileStream.read()) != -1) { byteStream.write(data); } } catch (IOException e) { throw e; } finally { try { fileStream.close(); } catch (Exception ex) { } } byte[] data = byteStream.toByteArray(); return data; } }