Java URL Download downloadFile(String urlPath, File file)

Here you can find the source of downloadFile(String urlPath, File file)

Description

Download a remote http file

License

Apache License

Parameter

Parameter Description
urlPath a parameter
file a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static void downloadFile(String urlPath, File file) throws IOException 

Method Source Code

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

import java.io.BufferedReader;
import java.io.BufferedWriter;

import java.io.File;

import java.io.FileWriter;
import java.io.IOException;

import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

public class Main {
    /**/*from w w w.j a  v a 2s  .c o  m*/
     * Download a remote http file
     * @param urlPath
     * @param file
     * @throws IOException
     */
    public static void downloadFile(String urlPath, File file) throws IOException {

        URL url = new URL(urlPath);
        URLConnection conn = url.openConnection();
        try (BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                BufferedWriter bw = new BufferedWriter(new FileWriter(file));) {
            String inputLine;
            while ((inputLine = br.readLine()) != null) {
                bw.write(inputLine);
            }
        }
    }
}

Related

  1. downloadFile(String url, String fileName)
  2. downloadFile(String url, String fileName)
  3. downloadFile(String url, String fileName)
  4. downloadFile(String url, String filePath, File parent)
  5. downloadFile(String url, String path)
  6. downloadFile(String urlString)
  7. downloadFile(String urlString, String filename)
  8. downloadFile(String urlToDownload, File locationToStore)
  9. downloadFile(URL fileUrl, File out)