DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Download A Web Page

05.27.2008
| 3763 views |
  • submit to reddit
        // Groovy code to download a web-page


def download(address, outfile)
{
    def file = new FileOutputStream(outfile)
    def out = new BufferedOutputStream(file)
    out << new URL(address).openStream()
    out.close()
}

download("http://www.google.com", "google.html");

    

Comments

Snippets Manager replied on Mon, 2008/04/21 - 12:49am

It can actually get even easier than that in groovy: def download(address, outfile) { new File(outfile).text = new URL(address).text } download "http://www.google.com", "google.html"