Here you can find the source of readFromFile(File file)
public static byte[] readFromFile(File file)
//package com.java2s; import java.io.DataInputStream; import java.io.File; import java.io.FileInputStream; public class Main { public static byte[] readFromFile(File file) { long fileSize = file.length(); byte[] fileData = new byte[(int) fileSize]; FileInputStream fileIn;//ww w .jav a 2s.c om DataInputStream dataIn; int offset = 0; int numRead = 0; try { fileIn = new FileInputStream(file); dataIn = new DataInputStream(fileIn); while (offset < fileData.length && (numRead = dataIn.read(fileData, offset, fileData.length - offset)) >= 0) { offset += numRead; } dataIn.close(); fileIn.close(); return fileData; } catch (Exception ex) { return null; } } }