码迷,mamicode.com
首页 > 编程语言 > 详细

多线程下载图片实例

时间:2020-06-20 19:18:47      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:下载图片   http   tst   comm   imp   stat   over   thread   commons   

package duoxiancheng;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.net.URL;

public class Downloader  extends Thread{
    
    String url;
    String name;
    @Override
    public void run() {
        Downnn downnn = new Downnn();
        downnn.dodd(url,name);
        System.out.println("下载:"+url+" name:"+name);
    }
    public Downloader(String url,String name){
        this.url=url;
        this.name=name;
    }

    public static void main(String[] args) {
        Downloader downloader=new Downloader("https://n.sinaimg.cn/fashion/590/w240h350/20200618/5242-ivffpcs0137589.jpg","1.jpg");
        Downloader downloader1=new Downloader("https://n.sinaimg.cn/fashion/590/w240h350/20200618/5242-ivffpcs0137589.jpg","2.jpg");
        Downloader downloader2=new Downloader("https://n.sinaimg.cn/fashion/590/w240h350/20200618/5242-ivffpcs0137589.jpg","3.jpg");
        downloader.start();
        downloader1.start();
        downloader2.start();

    }
}

class Downnn{
    public void dodd(String url,String name){
        try {
            FileUtils.copyURLToFile(new URL(url),new File(name));
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


}

多线程下载图片实例

标签:下载图片   http   tst   comm   imp   stat   over   thread   commons   

原文地址:https://www.cnblogs.com/itzyz/p/13169771.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!