Here you can find the source of downloadFile(String url, String path)
public static void downloadFile(String url, String path)
//package com.java2s; //License from project: Open Source License import java.io.IOException; import java.net.URL; import java.net.MalformedURLException; import java.io.BufferedInputStream; import java.io.BufferedInputStream; import java.io.FileOutputStream; public class Main { public static void downloadFile(String url, String path) { BufferedInputStream in = null; FileOutputStream fout = null; try {/*from w w w .j a v a 2s . c o m*/ in = new BufferedInputStream(new URL(url).openStream()); fout = new FileOutputStream(path); final byte data[] = new byte[1024]; int count; while ((count = in.read(data, 0, 1024)) != -1) { fout.write(data, 0, count); } } catch (MalformedURLException e) { System.err.println("An error occured while downloading a file (1)."); e.printStackTrace(); } catch (IOException e) { System.err.println("An error occured while downloading a file (2)."); e.printStackTrace(); } finally { // Close file IO's try { if (in != null) { in.close(); } if (fout != null) { fout.close(); } } catch (IOException e) { // We can't do anything. System.err.println("A critical error occured while downoading a file (3)."); e.printStackTrace(); return; } } } }