Java URL Download download(String url)

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

Description

download

License

Apache License

Declaration

public static byte[] download(String url) throws IOException 

Method Source Code


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

import java.io.*;
import java.net.URL;

public class Main {
    public static byte[] download(String url) throws IOException {
        final ByteArrayOutputStream result = new ByteArrayOutputStream();
        try (InputStream is = new URL(url).openStream()) {
            copy(is, result);//w  w  w.jav  a 2 s.  com
        }
        return result.toByteArray();
    }

    public static void copy(InputStream is, OutputStream os) throws IOException {
        final int bufferSize = 8192;
        final byte[] buffer = new byte[bufferSize];
        int readed;
        while ((readed = is.read(buffer, 0, bufferSize)) != -1) {
            os.write(buffer, 0, readed);
        }
    }
}

Related

  1. downImg(String filePath, String imageUrl, String fileName)
  2. download(final String sURL, final String sFilename)
  3. download(final URL url)
  4. download(String downloadUrlStr, String filename)
  5. download(String fileUrl, String savePath, String fileName)
  6. download(String url, String path)
  7. download(String url, String saveFile)
  8. download(String url, String toFile)
  9. download(String urlAddress, File file)