![5abbbfe867b8d3bc15521d66e4aac488.png](https://i-blog.csdnimg.cn/blog_migrate/049d764a833f0bfa5181548e8bf0bb7d.png)
工具类综合实验
这是一个多线程进行下载网页地址内容的程序!
这里用到了我们之前学习的 1. 异常 2. 字符串处理 3. 文件流 4. 多线程
一个非常综合的案例。。。。。
上代码
:
package test;
import java.net.URL;
import java.net.HttpURLConnection;
import java.io.File;
import java.io.RandomAccessFile;
import java.io.IOException;
import java.io.BufferedInputStream;
class DownloadManager
{
static final long unitSize=100*1024; //分配给每个下载线程的字节数
public static void main(String[] args) throws IOException
{
if(args.length!=2)
{
System.out.println("Usage java DownloadManager URL local_file_name");
return;
}
DownloadManager downloadManager=new DownloadManager();
downloadManager.doDownload(args[0],args[1]);
}
public void doDownload(String remoteFileUrl, String localFileName) throws IOException
{
long fileSize=this.getRemoteFileSize(remoteFileUrl);
this.createFi