Here you can find the source of loadData(File f)
public static byte[] loadData(File f) throws Exception
//package com.java2s; //License from project: Apache License import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] loadData(InputStream is) throws IOException { BufferedInputStream bis = null; byte[] data = null; byte[] tmp = new byte[1024]; int num = 0; bis = new BufferedInputStream(is); while ((num = bis.read(tmp)) > 0) { if (data == null) { data = new byte[num]; System.arraycopy(tmp, 0, data, 0, num); } else { byte[] old = data; data = new byte[old.length + num]; System.arraycopy(old, 0, data, 0, old.length); System.arraycopy(tmp, 0, data, old.length, num); }/*from ww w . java 2s . c o m*/ } return data; } public static byte[] loadData(File f) throws Exception { byte[] data = null; InputStream br = new FileInputStream(f); byte[] tmp = new byte[8192]; int num = 0; int len = 0; try { while ((num = br.read(tmp)) > 0) { if (data == null) { data = new byte[num]; System.arraycopy(tmp, 0, data, 0, num); } else { byte[] old = data; data = new byte[old.length + num]; System.arraycopy(old, 0, data, 0, old.length); System.arraycopy(tmp, 0, data, old.length, num); } len += num; } } finally { br.close(); } return data; } }