Java tutorial
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static byte[] readFully(File file) throws IOException { final InputStream in = new BufferedInputStream(new FileInputStream(file)); try { ByteArrayOutputStream bytes = new ByteArrayOutputStream(); byte[] buffer = new byte[1 << 20]; int count; while ((count = in.read(buffer)) != -1) { bytes.write(buffer, 0, count); } return bytes.toByteArray(); } finally { in.close(); } } public static void close(Closeable closable) { if (closable != null) { try { closable.close(); } catch (IOException e) { e.printStackTrace(); } } } }