Java URL Download nio download(URI source, File target)

Here you can find the source of download(URI source, File target)

Description

Downloads a file from the Internet

License

LGPL

Parameter

Parameter Description
source URI to file
target Local file to save to

Exception

Parameter Description
IOException an exception

Declaration

public static void download(URI source, File target) throws IOException 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.io.*;

import java.net.URI;

import java.nio.channels.Channels;

import java.nio.channels.ReadableByteChannel;

public class Main {
    /**//  ww w  .j  a v  a 2s .  com
     * <p>Downloads a file from the Internet</p>
     * @param source URI to file
     * @param target Local file to save to
     * @throws IOException
     */
    public static void download(URI source, File target) throws IOException {
        ReadableByteChannel rbc = Channels.newChannel(source.toURL().openStream());
        FileOutputStream fos = new FileOutputStream(target, false);
        fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
    }
}

Related

  1. download(String from, String to)
  2. download(String link, File destFile)
  3. download(String url, File output)
  4. download(String url, String destPath)
  5. download(String url, String inputFile, String outputPath, String outputFile)
  6. download(URL link, File outputFile)
  7. download(URL url, File out)
  8. download(URL url, File out)
  9. download(URL url, Path location)