Java URL Download nio downloadFileToDirectory(String url, File destination)

Here you can find the source of downloadFileToDirectory(String url, File destination)

Description

download File To Directory

License

Open Source License

Declaration

public static void downloadFileToDirectory(String url, File destination) throws Exception 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileOutputStream;

import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;

public class Main {
    public static void downloadFileToDirectory(String url, File destination) throws Exception {
        URL website = new URL(url);
        ReadableByteChannel rbc = Channels.newChannel(website.openStream());
        @SuppressWarnings("resource")
        FileOutputStream fos = new FileOutputStream(destination.getAbsolutePath());
        fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
    }//from   w  ww .  j  av a  2 s.c o  m
}

Related

  1. downloadFile(String urlPath, String local)
  2. downloadFile(URL downloadUrl, File destination)
  3. downloadFile(URL url, File output)
  4. downloadFile(URL url, File targetFile)
  5. downloadFileNIO(FileChannel fileChannel, SocketChannel socketChannel)
  6. downloadFirstLineFromInternetQuietly(URL url)
  7. downloadFromHttpUrl(String destPkgUrl, FileOutputStream outputStream)
  8. downloadFromInternet(URL url, File downloadTo)
  9. downloadImage(String src, Path saveFolder)