Java tutorial
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; public class Main { public static byte[] read(File file) throws IOException { byte[] buffer = new byte[(int) file.length()]; InputStream ios = null; try { ios = new FileInputStream(file); if (ios.read(buffer) == -1) throw new IOException("EOF reached while trying to read the whole file"); } finally { try { if (ios != null) ios.close(); } catch (IOException e) { } } return buffer; } }