DownUtil类
package loading;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import org.omg.CORBA.portable.InputStream;
public class DownUtil {
//定义下载资源的路径
private String path;
//定义所下载文件的保存位置
private String targetFile;
//定义需要使用多少个线程下载资源
private int threadNum;
//定义下载的线程对象
private DownThreads[] threads;
//定义下载文件的总大小
private int fileSize;
public DownUtil(String path,String targetFile,int threadNum)
{
this.path=path;
this.targetFile=targetFile;
this.threadNum=threadNum;
//初始化threads数组
threads=new DownThreads[threadNum];
}
//定义下载函数
public void download() throws Exception
{
URL url=new URL(path);
HttpURLConnection conn=(HttpURLConnection) url.openConnection();
conn.setConnectTimeout(5000);
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept",
"image/gif