Here you can find the source of downloadFromInternet(URL url, File downloadTo)
public static void downloadFromInternet(URL url, File downloadTo) throws IOException
//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.net.URL; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; public class Main { public static void downloadFromInternet(URL url, File downloadTo) throws IOException { ReadableByteChannel rbc = null; FileOutputStream fos = null; try {/*w w w.j a va 2 s. c om*/ rbc = Channels.newChannel(url.openStream()); fos = new FileOutputStream(downloadTo); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); } finally { closeQuietly(rbc); closeQuietly(fos); } } /** * Close a stream quietly because we honestly don't care if a stream.close() * throws IOException */ public static void closeQuietly(Closeable cl) { if (cl == null) { return; } try { cl.close(); } catch (IOException ioe) { // do nothing } } }