Here you can find the source of readFileToByteArray(String pathToFile)
public static byte[] readFileToByteArray(String pathToFile)
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.io.RandomAccessFile; public class Main { public static byte[] readFileToByteArray(String pathToFile) { byte[] result = null; try {//from ww w .j ava2 s. co m File file = new File(pathToFile); if (file.length() <= Integer.MAX_VALUE) { result = new byte[(int) file.length()]; @SuppressWarnings("resource") RandomAccessFile raf = new RandomAccessFile(file, "r"); raf.readFully(result); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return result; } }