Here you can find the source of getBytesFromUrl(String url)
public static byte[] getBytesFromUrl(String url) throws Exception
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; public class Main { public static byte[] getBytesFromUrl(String url) throws Exception { return readInputStream(getRequest(url)); }/*from ww w. j ava 2 s. c o m*/ public static byte[] readInputStream(InputStream inStream) throws Exception { ByteArrayOutputStream outSteam = new ByteArrayOutputStream(); byte[] buffer = new byte[4096]; int len = 0; while ((len = inStream.read(buffer)) != -1) { outSteam.write(buffer, 0, len); } outSteam.close(); inStream.close(); return outSteam.toByteArray(); } public static InputStream getRequest(String path) throws Exception { URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("GET"); conn.setConnectTimeout(5000); if (conn.getResponseCode() == 200) { return conn.getInputStream(); } return null; } }