Here you can find the source of downloadFile(String urlPath, File file)
Parameter | Description |
---|---|
urlPath | a parameter |
file | a parameter |
Parameter | Description |
---|---|
IOException | an exception |
public static void downloadFile(String urlPath, File file) throws IOException
//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); } } } }