Here you can find the source of getBytesFromFile(File file)
public static byte[] getBytesFromFile(File file)
//package com.java2s; //License from project: Apache License import java.io.*; public class Main { public static byte[] getBytesFromFile(File file) { byte[] ret = null; try {/*from w w w . j av a 2 s . c o m*/ if (file == null) { // log.error("helper:the file is null!"); return null; } FileInputStream in = new FileInputStream(file); ByteArrayOutputStream out = new ByteArrayOutputStream(4096); byte[] b = new byte[4096]; int n; while ((n = in.read(b)) != -1) { out.write(b, 0, n); } in.close(); out.close(); ret = out.toByteArray(); } catch (IOException e) { // log.error("helper:get bytes from file process error!"); e.printStackTrace(); } return ret; } }