Here you can find the source of getBytesFromFile(String filePath)
public static byte[] getBytesFromFile(String filePath)
//package com.java2s; //License from project: Apache License import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; public class Main { public static byte[] getBytesFromFile(String filePath) { return getBytesFromFile(new File(filePath)); }/*from w w w.j a v a 2 s . c o m*/ public static byte[] getBytesFromFile(File f) { if (f == null) { return null; } try { FileInputStream stream = new FileInputStream(f); ByteArrayOutputStream out = new ByteArrayOutputStream(1000); byte[] b = new byte[1000]; int n; while ((n = stream.read(b)) != -1) { out.write(b, 0, n); } stream.close(); out.close(); return out.toByteArray(); } catch (IOException e) { } return null; } }