Here you can find the source of downloadUrl(String urlstring, File file)
public static boolean downloadUrl(String urlstring, File file)
//package com.java2s; //License from project: Apache License import java.io.*; import java.net.URL; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; public class Main { public static boolean downloadUrl(String urlstring, File file) { try {/* w w w . j a va 2s . c o m*/ URL url = new URL(urlstring); ReadableByteChannel rbc = Channels.newChannel(url.openStream()); FileOutputStream fos = new FileOutputStream(file); fos.getChannel().transferFrom(rbc, 0, 1 << 24); return true; } catch (Exception e) { e.printStackTrace(); return false; } } public static boolean downloadUrl(String urlstring, String filename) { return downloadUrl(urlstring, new File(filename)); } }