Here you can find the source of file2byte(File file)
public static byte[] file2byte(File file)
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; public class Main { public static byte[] file2byte(String path) { byte[] data = null; data = file2byte(new File(path)); return data; }// w ww.jav a2 s . co m public static byte[] file2byte(File file) { byte[] data = null; FileInputStream input = null; try { input = new FileInputStream(file); ByteArrayOutputStream output = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int numBytesRead = 0; while ((numBytesRead = input.read(buf)) != -1) { output.write(buf, 0, numBytesRead); } data = output.toByteArray(); output.close(); input.close(); } catch (FileNotFoundException ex1) { ex1.printStackTrace(); } catch (IOException ex1) { ex1.printStackTrace(); } return data; } }