Here you can find the source of downloadFile(String inputUrl, String destination)
public synchronized static Path downloadFile(String inputUrl, String destination)
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Main { public synchronized static Path downloadFile(String inputUrl, String destination) { String filename = Paths.get(inputUrl).getFileName().toString(); URL url;/*w w w.ja va 2 s . c om*/ try { url = new URL(inputUrl); } catch (MalformedURLException e) { return null; } Path path; URLConnection con; try { con = url.openConnection(); path = Paths.get(destination + File.separator + filename); try (InputStream stream = con.getInputStream()) { Files.copy(stream, path); } return path; } catch (IOException e) { return null; } } }