Here you can find the source of downloadFile(String url, File output)
Parameter | Description |
---|---|
url | The URL from where to download the file from. |
output | The file where the file will be stored. |
Parameter | Description |
---|---|
MalformedURLException | an exception |
IOException | an exception |
public static void downloadFile(String url, File output) throws MalformedURLException, IOException
//package com.java2s; //License from project: Open Source License import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; public class Main { /**/*from w w w .j av a 2s .c o m*/ * Downloads a file from the specified URIL and saves it at the specified location. * * @param url The URL from where to download the file from. * @param output The file where the file will be stored. * @throws MalformedURLException * @throws IOException */ public static void downloadFile(String url, File output) throws MalformedURLException, IOException { final URL website = new URL(url); final ReadableByteChannel rbc = Channels.newChannel(website.openStream()); final FileOutputStream fos = new FileOutputStream(output); fos.getChannel().transferFrom(rbc, 0, 1 << 24); fos.close(); } }