Java URL Download nio downloadToFile(URL url, File file)

Here you can find the source of downloadToFile(URL url, File file)

Description

download To File

License

Open Source License

Declaration

public static void downloadToFile(URL url, File file) throws IOException 

Method Source Code

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

import java.io.*;
import java.net.*;
import java.nio.channels.Channels;

import java.nio.channels.ReadableByteChannel;

public class Main {
    public static void downloadToFile(URL url, File file) throws IOException {
        file.getParentFile().mkdirs();/*from   w  w w  .  j  a  va 2  s.  c om*/
        ReadableByteChannel rbc = Channels.newChannel(url.openStream());
        FileOutputStream fos = new FileOutputStream(file);
        fos.getChannel().transferFrom(rbc, 0, 1 << 24);
        fos.close();
    }
}

Related

  1. downloadFirstLineFromInternetQuietly(URL url)
  2. downloadFromHttpUrl(String destPkgUrl, FileOutputStream outputStream)
  3. downloadFromInternet(URL url, File downloadTo)
  4. downloadImage(String src, Path saveFolder)
  5. downloadToFile(String filename, String urlString)
  6. downloadToString(String url)
  7. downloadUrl(String urlstring, File file)