网图下载
package exception.Demo03;
import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.net.URL;
public class TestThread2 extends Thread {
private String url;
private String name;
public TestThread2(String url,String name){
this.url = url;
this.name = name;
}
@Override
public void run() {
WedDownloader wedDownloader = new WedDownloader();
wedDownloader.downloader(url,name);
System.out.println("下载的文件名为:"+name);
}
public static void main(String[] args) {
TestThread2 t1 = new TestThread2("https://img-home.csdnimg.cn/images/20230524081746.jpg","1.jpg");
TestThread2 t2 = new TestThread2("https://img-blog.csdnimg.cn/img_convert/3e6f12d3451111c4780f7512d46f55be.png","2.jpg");
TestThread2 t3 = new TestThread2("https://img-blog.csdnimg.cn/img_convert/5af038d9b6bf11293fa105c67926e355.png","3.jpg");
t1.start();
t2.start();
t3.start();
}
}
class WedDownloader{
public void downloader(String url,String name){
try {
FileUtils.copyURLToFile(new URL(url),new File(name));
} catch (IOException e) {
e.printStackTrace();
System.out.println("IO异常,downleader方法,出现问题");
}
}
}