Java URL Download nio downloadAsync(String url, File file)

Here you can find the source of downloadAsync(String url, File file)

Description

download Async

License

Open Source License

Declaration

public static void downloadAsync(String url, File file)
        throws IOException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;

public class Main {

    public static void downloadAsync(String url, File file)
            throws IOException {
        InputStream inputStream = new URL(url).openStream();
        ReadableByteChannel rbc = Channels.newChannel(inputStream);
        FileOutputStream fos = new FileOutputStream(file);
        fos.getChannel().transferFrom(rbc, 0, 1 << 24);
    }/*from   w  ww .j  a v a  2s  .com*/
}

Related

  1. download(URL link, File outputFile)
  2. download(URL url, File out)
  3. download(URL url, File out)
  4. download(URL url, Path location)
  5. download(URL url, String save)
  6. downloadFile(final String url, final String downloadPath)
  7. downloadFile(String fileName, String url)
  8. downloadFile(String fileURL, String folderPath)
  9. downloadFile(String inputUrl, String destination)