Here you can find the source of readFileAsByteArray(File file)
public static byte[] readFileAsByteArray(File file) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class Main { public static byte[] readFileAsByteArray(File file) throws IOException { ByteBuffer bb;/*from w ww .j a v a 2 s . c o m*/ FileChannel fc = null; try { fc = new FileInputStream(file).getChannel(); bb = ByteBuffer.allocate((int) fc.size()); fc.read(bb); } finally { if (fc != null) fc.close(); } return bb.array(); } }