Here you can find the source of downloadURL(URL url, String localPath)
public static String downloadURL(URL url, String localPath) throws IOException
//package com.java2s; /*/*from www. j a va2 s. c o m*/ * Copyright 2010-2011, Sikuli.org * Released under the MIT License. * */ import java.net.URL; import java.io.*; public class Main { final static int DOWNLOAD_BUFFER_SIZE = 153600; public static String downloadURL(URL url, String localPath) throws IOException { InputStream reader = url.openStream(); String[] path = url.getPath().split("/"); String filename = path[path.length - 1]; File fullpath = new File(localPath, filename); FileOutputStream writer = new FileOutputStream(fullpath); byte[] buffer = new byte[DOWNLOAD_BUFFER_SIZE]; int totalBytesRead = 0; int bytesRead = 0; while ((bytesRead = reader.read(buffer)) > 0) { writer.write(buffer, 0, bytesRead); totalBytesRead += bytesRead; } reader.close(); writer.close(); return fullpath.getAbsolutePath(); } }