JAVA How to download multiple files at once __java

Source: Internet
Author: User

Https://zhidao.baidu.com/question/1446055057527183940.html


Import Java.io.BufferedInputStream;
Import Java.io.File;
Import java.io.FileNotFoundException;
Import Java.io.FileOutputStream;
Import java.io.IOException;
Import java.net.HttpURLConnection;
Import Java.net.URL;
Import Java.net.URLDecoder;
Import Java.util.Vector;
Import java.util.concurrent.Callable;
Import Java.util.concurrent.ExecutorService;
Import java.util.concurrent.Executors;
 
Import Java.util.concurrent.Future; /** * This example uses synchronous downloads based on JDK httpurlconnection, which are downloaded sequentially * If you download multiple tasks at the same time, you can use multithreading * @author ak1ng * */public class Demo1 {PU Blic static void Main (string[] args) {//download list vector<string> downloadlist = new Vector<string&gt
        ;();
        Add Download Address Downloadlist.add (");
        Downloadlist.add (");
    Download (downloadlist); /** * Download/static void download (Vector<string> downloadlist) {//thread pool Exec
        Utorservice pool = null;
        HttpURLConnection connection = null;
     Cycle download   try {for (int i = 0; i < downloadlist.size (); i++) {pool = Executors.newcachedthreadpo
                OL ();
                Final String url = downloadlist.get (i);
                String filename = GetFileName (Downloadlist.get (i));
                SYSTEM.OUT.PRINTLN ("Downloading the first" + (i+1) + "files, Address:" + URL); future 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.