The code snippet below show you how to use the FileUtils.copyURLToFile(URL url, File destination) method of the Apache Commons IO library to help you to copy a URL directly into a file.
package org.kodejava.example.commons.io;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.net.URL;
public class URLToFile {
public static void main(String[] args) {
try {
URL url = new URL("http://www.kodejava.org");
File destination = new File("kodejava.html");
//
// Copy bytes from the URL to the destination file.
//
FileUtils.copyURLToFile(url, destination);
} catch (IOException e) {
e.printStackTrace();
}
}
}