Here you can find the source of download(URL url)
public static byte[] download(URL url) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.URL; import java.net.URLConnection; public class Main { public static byte[] download(URL url) throws IOException { return download(url.toString(), 60000, 60000); }/*from w w w .j a v a 2 s.c o m*/ public static byte[] download(String url, int connectTimeout, int readTimeout) throws IOException { URLConnection con = new URL(url).openConnection(); con.setConnectTimeout(connectTimeout); con.setReadTimeout(readTimeout); InputStream in = con.getInputStream(); byte[] content; try { content = toBytes(in); } finally { in.close(); } return content; } private static byte[] toBytes(InputStream in) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); copy(in, out); return out.toByteArray(); } private static void copy(InputStream in, OutputStream out) throws IOException { byte[] buff = new byte[256]; int len = in.read(buff); while (len != -1) { out.write(buff, 0, len); len = in.read(buff); } } }