The following java method is a simple way to download a file stored on the internet.

Let’s say you want to download the file at the address http://www.yourdomain.com/file.zip and then you want to store it into C:, with the following method you’ll have to do the following simple call:

downloadAndStoreFile(“http://www.yourdomain.com/file.zip”, “C:\\file.zip”);

 

and here you are the method:

    private void downloadAndStoreFile(String fileAddress, String pathToDestination)
    {
        try {
            URL fileToDownload = new URL(fileAddress);
            ReadableByteChannel rbc = Channels.newChannel(fileToDownload.openStream());
            FileOutputStream fos = new FileOutputStream(pathToDestination);
            fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
        } catch (IOException ex) {
            System.out.println(ex);
        }
        
    }

 

Gg1