Here you can find the source of readURLToByteArray(URL url)
public static byte[] readURLToByteArray(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.net.URL; public class Main { public static byte[] readURLToByteArray(URL url) throws IOException { return readInputStreamToByteArray(url.openStream()); }//w w w . j av a2 s. co m public static byte[] readInputStreamToByteArray(InputStream inputStream) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] buff = new byte[1024]; int read; while ((read = inputStream.read(buff)) != -1) { out.write(buff, 0, read); } return out.toByteArray(); } }