Java URL Download nio download(String url, String inputFile, String outputPath, String outputFile)

Here you can find the source of download(String url, String inputFile, String outputPath, String outputFile)

Description

download

License

Open Source License

Declaration

public static Path download(String url, String inputFile, String outputPath, String outputFile)
            throws Exception 

Method Source Code


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

import java.io.InputStream;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

public class Main {
    public static Path download(String url, String inputFile, String outputPath, String outputFile)
            throws Exception {
        return download(url + inputFile, outputPath, outputFile);
    }/* w w  w .  j  a v a2s.c  o  m*/

    public static Path download(String url, String outputPath, String outputFile) throws Exception {
        Path output = Paths.get(outputPath);
        if (Files.notExists(output)) {
            Files.createDirectory(output);
        }
        URI u = URI.create(url);
        Path file = output.resolve(outputFile);

        try (InputStream in = u.toURL().openStream()) {
            Files.copy(in, file, StandardCopyOption.REPLACE_EXISTING);
        }
        return file;
    }
}

Related

  1. download(File dist, URL src)
  2. download(String from, String to)
  3. download(String link, File destFile)
  4. download(String url, File output)
  5. download(String url, String destPath)
  6. download(URI source, File target)
  7. download(URL link, File outputFile)
  8. download(URL url, File out)
  9. download(URL url, File out)