Here you can find the source of downloadFileToDirectory(String url, File destination)
public static void downloadFileToDirectory(String url, File destination) throws Exception
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileOutputStream; import java.net.URL; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; public class Main { public static void downloadFileToDirectory(String url, File destination) throws Exception { URL website = new URL(url); ReadableByteChannel rbc = Channels.newChannel(website.openStream()); @SuppressWarnings("resource") FileOutputStream fos = new FileOutputStream(destination.getAbsolutePath()); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); }//from w ww . j av a 2 s.c o m }