Here you can find the source of file2byte(String path)
public static byte[] file2byte(String path)
//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; }/*from ww w .j a v a 2 s. c o 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; } }