Here you can find the source of download(URL url, File out)
Parameter | Description |
---|---|
url | source url |
out | file to write content to |
public static void download(URL url, File out) throws IOException
//package com.java2s; //License from project: Apache License import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; public class Main { /**//w w w. j av a2s .c o m * Copies the content of a URL to a local file. * * @param url source url * @param out file to write content to */ public static void download(URL url, File out) throws IOException { ReadableByteChannel rbc = Channels.newChannel(url.openStream()); FileOutputStream fos = new FileOutputStream(out); fos.getChannel().transferFrom(rbc, 0, 1 << 24); fos.close(); rbc.close(); } /** * Copies the content of a URL to a local file. * * @param url source url * @param out file to write content to */ public static void download(String url, File out) throws IOException { URL u = new URL(url); download(u, out); } }