Here you can find the source of download(URL url, Path location)
public static Path download(URL url, Path location) throws IOException
//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); } }