Java URL Download nio download(URL url, Path location)

Here you can find the source of download(URL url, Path location)

Description

download

License

Open Source License

Declaration

public static Path download(URL url, Path location) throws IOException 

Method Source Code


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

import java.io.FileOutputStream;
import java.io.IOException;

import java.net.URL;

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

import java.nio.file.Path;

public class Main {
    public static Path download(URL url, Path location) throws IOException {
        try (final ReadableByteChannel channel = Channels.newChannel(url.openStream());
                final FileOutputStream outputStream = new FileOutputStream(location.toString())) {
            outputStream.getChannel().transferFrom(channel, 0, Long.MAX_VALUE);
            return location;
        }/*  ww  w.  j av a 2 s.c o  m*/
    }

    public static Path download(String url, Path location) throws IOException {
        return download(new URL(url), location);
    }
}

Related

  1. download(String url, String inputFile, String outputPath, String outputFile)
  2. download(URI source, File target)
  3. download(URL link, File outputFile)
  4. download(URL url, File out)
  5. download(URL url, File out)
  6. download(URL url, String save)
  7. downloadAsync(String url, File file)
  8. downloadFile(final String url, final String downloadPath)
  9. downloadFile(String fileName, String url)