Here you can find the source of getBytes(File aFile)
public static byte[] getBytes(File aFile)
//package com.java2s; import java.io.*; public class Main { /**//w w w. ja v a 2s. c om * Returns bytes for a file. */ public static byte[] getBytes(File aFile) { // Return null if file is null, doesn't exist, isn't readable or is directory if (aFile == null) return null; if (!aFile.exists()) return null; if (!aFile.canRead()) return null; if (aFile.isDirectory()) return null; // Get file length, byte buffer, file stream, read bytes into buffer and close stream try { int length = (int) aFile.length(); byte bytes[] = new byte[length]; InputStream stream = new FileInputStream(aFile); stream.read(bytes, 0, length); stream.close(); return bytes; } // Re-throw exceptions catch (IOException e) { throw new RuntimeException(e); } } }