Java tutorial
//package com.java2s; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Main { public static byte[] readFileToByteArray(File file) { try { byte[] fileData = new byte[(int) file.length()]; DataInputStream dis = new DataInputStream(new FileInputStream(file)); dis.readFully(fileData); dis.close(); return fileData; } catch (IOException e) { return null; } } }