Here you can find the source of fileToBytes(File file)
public static byte[] fileToBytes(File file)
//package com.java2s; //License from project: Apache License import java.io.Closeable; import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Main { public static byte[] fileToBytes(File file) { FileInputStream fin = null; byte arr[] = new byte[(int) file.length()]; try {/* w ww . j a v a2 s . c o m*/ fin = new FileInputStream(file); fin.read(arr); } catch (IOException e) { throw new RuntimeException(e.getMessage(), e); } finally { close(fin); } return arr; } public static void close(Closeable... closes) { // RuntimeException re = null; if (closes == null) { return; } for (Closeable close : closes) { try { if (close != null) { close.close(); } } catch (IOException e) { // re = new RuntimeException(e.getMessage(), e); } } } }