Here you can find the source of download(File dist, URL src)
public static boolean download(File dist, URL src)
//package com.java2s; //License from project: Open Source License import java.io.Closeable; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; import java.nio.channels.Channels; import java.nio.channels.FileChannel; import java.nio.channels.ReadableByteChannel; public class Main { public static boolean download(File dist, URL src) { InputStream is = null;//from www.j a v a 2 s . c o m ReadableByteChannel in = null; FileOutputStream fos = null; FileChannel out = null; try { URLConnection connection = src.openConnection(); is = connection.getInputStream(); in = Channels.newChannel(is); fos = new FileOutputStream(dist); out = fos.getChannel(); out.transferFrom(in, 0, connection.getContentLength()); return true; } catch (IOException e) { return false; } finally { close(in, is, out, fos); } } public static void close(Closeable... closeables) { for (Closeable c : closeables) try { c.close(); } catch (IOException e) { /* ignore */ } } }