Java URL Download downloadBinary(URL BaseURL, String Name, File TargetDirectory)

Here you can find the source of downloadBinary(URL BaseURL, String Name, File TargetDirectory)

Description

download Binary

License

Apache License

Declaration

public static void downloadBinary(URL BaseURL, String Name, File TargetDirectory) throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.*;

import java.net.*;

public class Main {
    public static void downloadBinary(URL BaseURL, String Name, File TargetDirectory) throws IOException {
        URL TheURL = new URL(BaseURL, Name);
        File TestFile = new File(TargetDirectory, Name);
        downloadBinary(TheURL, TestFile);
    }//from w ww .ja va  2 s  .  com

    public static void downloadBinary(URL TheURL, File TestFile) throws IOException {
        OutputStream outf = new FileOutputStream(TestFile);
        String test = TheURL.toString();
        System.out.println(test);
        InputStream in = TheURL.openStream();
        downloadBinary(in, outf);
    }

    public static void downloadBinary(InputStream ins, OutputStream outf) throws IOException {
        byte[] holder = new byte[4096];
        InputStream in = new BufferedInputStream(ins);
        OutputStream out = new BufferedOutputStream(outf);
        int Nread = in.read(holder);
        int col = 0;
        while (Nread > -1) {
            out.write(holder, 0, Nread);
            Nread = in.read(holder);
            System.out.print(".");
            if (col++ > 60) {
                System.out.println();
                col = 0;
            }
        }
        System.out.println();
        in.close();
        out.close();
    }
}

Related

  1. download(URL url, File file)
  2. downloadAndExtract(String fileURL, String targetDirectory)
  3. downloadAndSaveImage(URL imageUrl, String path)
  4. downloadAndUnzip(String url, File location)
  5. downloadAsString(String url)
  6. downloadData(String url, String params)
  7. downloadDirectory(URL dirUrl, File destDir)
  8. downloadFile(File parent, String prefix, String suffix, URL url)
  9. downloadFile(File target, String urlStr)