Java URL Download download(String urlAddress, File file)

Here you can find the source of download(String urlAddress, File file)

Description

download

License

Open Source License

Declaration

public static void download(String urlAddress, File file) throws FileNotFoundException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import java.net.URL;

public class Main {
    public static void download(String urlAddress, File file) throws FileNotFoundException {
        file.getParentFile().mkdirs();/*from   w  ww  .j av a 2  s  . co m*/
        try {
            OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
            InputStream inputStream = new URL(urlAddress).openConnection().getInputStream();
            byte[] data = new byte[2048];
            int read = 0;
            while ((read = inputStream.read(data)) != -1) {
                outputStream.write(data, 0, read);
            }
            inputStream.close();
            outputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Related

  1. download(String fileUrl, String savePath, String fileName)
  2. download(String url)
  3. download(String url, String path)
  4. download(String url, String saveFile)
  5. download(String url, String toFile)
  6. download(String urlString)
  7. download(String urlString, File output)
  8. download(URL source, File destination)
  9. download(URL sourceUrl, File destinationFile)