Here you can find the source of download(URI source, File target)
Downloads a file from the Internet
Parameter | Description |
---|---|
source | URI to file |
target | Local file to save to |
Parameter | Description |
---|---|
IOException | an exception |
public static void download(URI source, File target) throws IOException
//package com.java2s; //License from project: LGPL import java.io.*; import java.net.URI; import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; public class Main { /**// ww w .j a v a 2s . com * <p>Downloads a file from the Internet</p> * @param source URI to file * @param target Local file to save to * @throws IOException */ public static void download(URI source, File target) throws IOException { ReadableByteChannel rbc = Channels.newChannel(source.toURL().openStream()); FileOutputStream fos = new FileOutputStream(target, false); fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); } }