How do I copy a URL into a file?

The code snippet below show you how to use the FileUtils.copyURLToFile(URL, File) method of the Apache Commons IO library to help you to copy the contents of a URL directly into a file.




public class URLToFile {
    public static void main(String[] args) {
        try {
            URL url = new URL("//");
            File destination = new File("google.html");

            // Copy bytes from the URL to the destination file.
            FileUtils.copyURLToFile(url, destination);
        } catch (IOException e) {

Maven Dependencies


Wayan Saryada

Programmer, runner, recreational diver, currently living in the island of Bali, Indonesia. Mostly programming in Java, creating web based application with Spring Framework, Hibernate / JPA.
  • I got a question: NetBeans tells me that the String "" cannot be converted to an URL.

    • Can you show the complete error message produced by NetBeans?