Here you can find the source of readFile(File file)
public static ByteBuffer readFile(File file) throws IOException
//package com.java2s; /*//w w w . ja v a 2 s . co m * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.nio.ByteBuffer; public class Main { public static ByteBuffer readFile(File file) throws IOException { byte[] buffer = new byte[(int) file.length()]; int bytesRead; try (FileInputStream fileReader = new FileInputStream(file)) { bytesRead = fileReader.read(buffer); } assert bytesRead == file.length() : file; return ByteBuffer.wrap(buffer); } }