Here you can find the source of fileToByteArray(final File f)
public static byte[] fileToByteArray(final File f) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Main { public static byte[] fileToByteArray(final File f) throws IOException { final FileInputStream is = new FileInputStream(f); final byte[] ret = new byte[(int) f.length()]; int p = 0; while (p < ret.length) p += is.read(ret, p, ret.length - p); is.close();//from w w w. j ava 2 s.c o m return ret; } }