Here you can find the source of download(URL url, File destination)
public static void download(URL url, File destination) throws IOException
//package com.java2s; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; public class Main { public static void download(URL url, File destination) throws IOException { byte[] buffer = new byte[4096]; int read, total = 0; URLConnection conn = url.openConnection(); conn.connect();// w ww.j a v a2s. c o m InputStream is = conn.getInputStream(); FileOutputStream out = new FileOutputStream(destination); while ((read = is.read(buffer)) > 0) { out.write(buffer, 0, read); total += read; } if (total < conn.getContentLength()) throw new IOException("Download truncated"); is.close(); out.close(); } }