| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 
 | package com.lcdzzz.demo01;
 
 
 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() {
 WebDownloader webDownloader = new WebDownloader();
 webDownloader.downloader(url,name);
 System.out.println("下载了文件名为"+name);
 }
 
 public static void main(String[] args) {
 TestThread2 t1 = new TestThread2("https://img0.baidu.com/it/u=3497851059,26175775&fm=253&fmt=auto&app=138&f=JPG?w=288&h=285","1.jpg");
 TestThread2 t2 = new TestThread2("https://img0.baidu.com/it/u=3497851059,26175775&fm=253&fmt=auto&app=138&f=JPG?w=288&h=285","2.jpg");
 TestThread2 t3 = new TestThread2("https://img0.baidu.com/it/u=3497851059,26175775&fm=253&fmt=auto&app=138&f=JPG?w=288&h=285","3.jpg");
 
 t1.start();
 t2.start();
 t3.start();
 }
 }
 
 
 class WebDownloader{
 
 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异常,downloader方法出现问题");
 }
 }
 }
 
 
 |