Java URL Load readURLToByteArray(URL url)

Here you can find the source of readURLToByteArray(URL url)

Description

read URL To Byte Array

License

Open Source License

Declaration

public static byte[] readURLToByteArray(URL url) throws IOException 

Method Source Code


//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();
    }
}

Related

  1. readUrlText(final URL url, final String encoding)
  2. readURLText(String urlPath, String encoding)
  3. readUrlText(String urlString)
  4. readURLText(URL url, StringBuffer errorText)
  5. readURLThrowException(final String url)
  6. readURLToString(URL u, String encoding)
  7. saveFile(final URL url, final File file)
  8. saveFileFromURL(URL url, File destinationFile)
  9. saveImage(String imageUrl, String destinationFile)