Here you can find the source of readHttpFile(String fileUrl, String referer)
public static byte[] readHttpFile(String fileUrl, String referer) throws IOException
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; import java.net.URL; public class Main { private final static int FILE_READ_BUFFER_SIZE = 4096; public static byte[] readHttpFile(String fileUrl, String referer) throws IOException { InputStream inputStream = null; ByteArrayOutputStream fileContent = null; try {/* w ww . j a v a 2s.c o m*/ URL url = new URL(fileUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); if (referer != null) { connection.setRequestProperty("Referer", referer); } inputStream = connection.getInputStream(); fileContent = new ByteArrayOutputStream(); byte[] buffer = new byte[FILE_READ_BUFFER_SIZE]; int n = 0; while (-1 != (n = inputStream.read(buffer))) { fileContent.write(buffer, 0, n); } } finally { if (inputStream != null) { inputStream.close(); } if (fileContent != null) { fileContent.close(); } } return fileContent.toByteArray(); } }