Here you can find the source of readFileBytes(String filename)
static byte[] readFileBytes(String filename) throws IOException
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; public class Main { static byte[] readFileBytes(String filename) throws IOException { File file = new File(filename); InputStream is = new FileInputStream(file); byte[] result = new byte[(int) file.length()]; int count = 0; while (count < result.length) { int r = is.read(result, count, result.length - count); if (r < 0) { break; }// w ww. j a v a 2 s .co m count += r; } is.close(); return result; } }