Here you can find the source of getBytes(File f)
static byte[] getBytes(File f) throws IOException
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.io.IOException; public class Main { static byte[] getBytes(InputStream is) throws IOException { int available = is.available(); byte[] tmpBuf = new byte[available]; int size = 0; int currentPointer = 0; byte[] result = null; while ((size = is.read(tmpBuf)) != -1) { result = updateBuffer(result, tmpBuf, currentPointer, size); currentPointer += size;/*from www. ja v a 2 s .c o m*/ } return result; } static byte[] getBytes(File f) throws IOException { FileInputStream fis = new FileInputStream(f.getAbsolutePath()); byte[] result = getBytes(fis); fis.close(); return result; } static byte[] updateBuffer(byte[] buf1, byte[] buf2, int currentPointer, int size) { if (size <= 0) { return buf2; } if (buf1 == null || buf1.length < currentPointer + size) { buf1 = new byte[currentPointer + size]; } System.arraycopy(buf2, 0, buf1, currentPointer, size); return buf1; } }