Here you can find the source of readFile(File file)
public static byte[] readFile(File file) throws IOException
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Main { public static final int MAX_MEDIA_FILE_LENGTH = 1 * 1024 * 1024; public static byte[] readFile(File file) throws IOException { FileInputStream fis = new FileInputStream(file); try {/*w w w . j a v a 2s . co m*/ int fileLen = fis.available(); if (fileLen > MAX_MEDIA_FILE_LENGTH) { return null; } byte[] data = new byte[fileLen]; fis.read(data); return data; } finally { if (fis != null) { fis.close(); } } } }