public static byte[] readFile(URL url) throws IOException {
  ByteQueue q=new ByteQueue();
  InputStream is=url.openStream();
  try {
    byte[] buf=new byte[1024];
    for (; ; ) {
      int bytesRead=is.read(buf);
      if (bytesRead == -1)       break;
      q.put(buf,0,bytesRead);
    }
    byte[] result=new byte[(int)q.getBytesWritten()];
    q.get(result);
    return result;
  }
  finally {
    is.close();
  }
}

public static byte [ ] readFile ( URL url ) throws IOException { ByteQueue q = new ByteQueue ( ) ; InputStream is = url . openStream ( ) ; try { byte [ ] buf = new byte [ 1024 ] ; for ( ; ; ) { int bytesRead = is . read ( buf ) ; if ( bytesRead == - 1 ) break ; q . put ( buf , 0 , bytesRead ) ; } byte [ ] result = new byte [ ( int ) q . getBytesWritten ( ) ] ; q . get ( result ) ; return result ; } finally { is . close ( ) ; } }
reads entire binary file to a byte array
