Friday 1 August 2014

Download file from Internet using Java

import java.nio.channels.*;
import java.net.*;
import java.io.*;

public class DownloadFile {
    public static void main(String args[]) throws Exception{
        URL website = new URL("http://courses.coreservlets.com/Course-Materials/pdf/struts/01-Struts-Intro.pdf");
        ReadableByteChannel rbc = Channels.newChannel(website.openStream());
        FileOutputStream fos = new FileOutputStream("structs.pdf");
        fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
        fos.close();
        rbc.close();
    }
}


                                                             Home

No comments:

Post a Comment