Here you can find the source of downloadToFile(URL url, File file)
public static void downloadToFile(URL url, File file) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.*; import java.net.*; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; public class Main { public static void downloadToFile(URL url, File file) throws IOException { file.getParentFile().mkdirs();/*from w w w . j a va 2 s. c om*/ ReadableByteChannel rbc = Channels.newChannel(url.openStream()); FileOutputStream fos = new FileOutputStream(file); fos.getChannel().transferFrom(rbc, 0, 1 << 24); fos.close(); } }