Here you can find the source of readByte(String filePath)
public static byte[] readByte(String filePath)
//package com.java2s; //License from project: Apache License import java.io.*; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class Main { public static byte[] readByte(String filePath) { try {//ww w. ja va 2s . c o m FileInputStream fis = new FileInputStream(filePath); FileChannel channel = fis.getChannel(); ByteBuffer byteBuffer = ByteBuffer.allocate((int) channel.size()); while ((channel.read(byteBuffer)) > 0) { // do nothing // System.out.println("reading"); } channel.close(); fis.close(); return byteBuffer.array(); } catch (IOException e) { e.printStackTrace(); } return null; } }