Here you can find the source of getBytesFromFile(String filepath)
private static byte[] getBytesFromFile(String filepath) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; public class Main { private static byte[] getBytesFromFile(String filepath) throws IOException { File file = new File(filepath); InputStream is = new FileInputStream(file); long length = file.length(); byte[] bytes = new byte[(int) length]; int offset = 0; int numRead = 0; while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) { offset += numRead;//from w ww . java 2 s . c o m } is.close(); return bytes; } }