标签:下载图片 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