Java tutorial
//package com.java2s; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Main { public static byte[] readFile(File file) throws IOException { int len = (int) file.length(); if (len == 0) { return new byte[0]; } byte[] data = null; BufferedInputStream bis = null; try { FileInputStream fis = new FileInputStream(file); bis = new BufferedInputStream(fis); data = new byte[len]; bis.read(data); } finally { if (bis != null) { try { bis.close(); } catch (IOException e) { } } } return data; } }