Here you can find the source of downloadURL(String url, String outFile)
public static void downloadURL(String url, String outFile) throws FileNotFoundException, MalformedURLException, IOException
//package com.java2s; //License from project: Creative Commons License import java.io.*; import java.net.*; public class Main { public static void downloadURL(String url, String outFile) throws FileNotFoundException, MalformedURLException, IOException { write((new URL(url)).openStream(), outFile); }//from w w w .ja va 2 s.c om public static void write(InputStream in, OutputStream out, int maxSizeInBytes) throws IOException { int totalBytes = 0; try { totalBytes = 0; int bytesRead = 0; byte[] buf = new byte[2048]; while ((bytesRead = in.read(buf)) != -1) { out.write(buf, 0, bytesRead); totalBytes += bytesRead; if (totalBytes > maxSizeInBytes) { throw new IOException("Write failed: input stream exceeded the maximum " + maxSizeInBytes + " bytes in size."); } } } finally { if (out != null) { out.close(); } } } public static void write(InputStream in, String outFile) throws FileNotFoundException, IOException { write(in, new File(outFile), Integer.MAX_VALUE); } public static void write(InputStream in, File outFile, int maxSizeInBytes) throws FileNotFoundException, IOException { FileOutputStream fos = new FileOutputStream(outFile); write(in, fos, maxSizeInBytes); fos.close(); } }