Here you can find the source of readFromUrl(URL url)
public static byte[] readFromUrl(URL url) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.net.URL; public class Main { public static byte[] readFromUrl(URL url) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[8192]; int i;//from www . j a va 2 s .co m try (InputStream is = url.openStream()) { while ((i = is.read(buffer)) != -1) { baos.write(buffer, 0, i); } } return baos.toByteArray(); } }