Java URL Load readBytesFromURL(String url)

Here you can find the source of readBytesFromURL(String url)

Description

read Bytes From URL

License

LGPL

Declaration

public static byte[] readBytesFromURL(String url) throws Throwable 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.io.ByteArrayOutputStream;

import java.io.InputStream;

import java.net.URL;

public class Main {
    public static byte[] readBytesFromURL(String url) throws Throwable {

        URL u = new URL(url);

        InputStream in;//from  w w  w .  jav  a2 s  . co m

        in = u.openStream();

        ByteArrayOutputStream baos = new ByteArrayOutputStream(1024 * 1024 * 5);

        byte[] b = new byte[1024];

        int read;

        while ((read = in.read(b)) > 0) {
            baos.write(b, 0, read);
        }

        return baos.toByteArray();
    }
}

Related

  1. read(URL file)
  2. read(URL url, String charsetName)
  3. readAsString(URL url)
  4. readAsStringUTF8(URL url)
  5. readBytes(URL url)
  6. readBytesFromUrl(URL url)
  7. readContent(URL url)
  8. readContentFromFile(URL u, String encoding)
  9. readContents(URL url)