public static byte[] readFileToByteArray(File file) throws IOException {
  InputStream in=null;
  try {
    in=openInputStream(file);
    return IOUtils.toByteArray(in,file.length());
  }
  finally {
    IOUtils.closeQuietly(in);
  }
}

public static byte [ ] readFileToByteArray ( File file ) throws IOException { InputStream in = null ; try { in = openInputStream ( file ) ; return IOUtils . toByteArray ( in , file . length ( ) ) ; } finally { IOUtils . closeQuietly ( in ) ; } }
reads the contents of a file into a byte array . the file is always closed .
