Here you can find the source of readFile(String name)
public static byte[] readFile(String name)
//package com.java2s; //License from project: Open Source License import java.io.RandomAccessFile; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class Main { public static byte[] readFile(String name) { try {/* ww w. j ava2s .co m*/ RandomAccessFile raf = new RandomAccessFile(name, "r"); ByteBuffer buf = raf.getChannel().map(FileChannel.MapMode.READ_ONLY, 0, raf.length()); try { if (buf.hasArray()) { return buf.array(); } else { byte[] array = new byte[buf.remaining()]; buf.get(array); return array; } } finally { raf.close(); } } catch (Exception e) { e.printStackTrace(); } return null; } }