import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOExceptionList;
import java.io.File;
import java.io.IOException;
import java.net.URL;
public class test2Thread extends Thread {
private String url;
private String name;
public test2Thread(String url,String name){
this.url=url;
this.name=name;
}
public void run(){
WebDownloader webDownloader=new WebDownloader();
webDownloader.downloader(url,name);
System.out.println("下载了文件名为"+name);
}
public static void main(String[] args) {
test2Thread t1=new test2Thread
("https://www.jgxy.xmu.edu.cn/uploads2/img/2021/10/08/2021100814195593250.jpg","1.jpg");
test2Thread t2=new test2Thread
("http://i0.hdslb.com/bfs/face/95823274c36951a15ca12e3b05078859c536f4a4.jpg","2.jpg");
t1.start();
t2.start();
}
}
class WebDownloader{
public void downloader(String url,String name){
try {
FileUtils.copyURLToFile(new URL(url),new File(name));
}catch (IOException e){
e.printStackTrace();
}
}
}
多线程实现图片下载1028更新
最新推荐文章于 2024-08-04 11:07:52 发布