Java 的 HTTP 文件队列下载
while ( (size = bis.read(buf)) != -1)
fos.write(buf, 0, size);
fos.close();
bis.close();
httpUrl.disconnect();
}
/**
* 设置代理服务器
*
* @param proxy String
* @param proxyPort String
*/
public void setProxyServer(String proxy, String proxyPort) {
//设置代理服务器
System.getProperties().put("proxySet", "true");
System.getProperties().put("proxyHost", proxy);
System.getProperties().put("proxyPort", proxyPort);
}
/**
* 设置认证用户名与密码
*
* @param uid String
* @param pwd String
*/
public void setAuthenticator(String uid, String pwd) {
Authenticator.setDefault(new MyAuthenticator(uid, pwd));
}
/**
* 主方法(用于测试)
*
* @param argv String[]
*/
public static void main(String argv[]) {
HttpGet oInstance = new HttpGet();
try {
//增加下载列表(此处用户可以写入自己代码来增加下载列表)
oInstance.addItem("http://www.ebook.com/java/网络编程001.zip","./网络编程1.zip");
oInstance.addItem("http://www.ebook.com/java/网络编程002.zip","./网络编程2.zip");
oInstance.addItem("http://www.ebook.com/java/网络编程003.zip","./网络编程3.zip");
oInstance.addItem("http://www.ebook.com/java/网络编程004.zip","./网络编程4.zip");
oInstance.addItem("http://www.ebook.com/java/网络编程005.zip","./网络编程5.zip");
oInstance.addItem("http://www.ebook.com/java/网络编程006.zip","./网络编程6.zip");
oInstance.addItem("http://www.ebook.com/java/网络编程007.zip","./网络编程7.zip");
//开始下载
oInstance.downLoadByList();
}
catch (Exception err) {
System.out.println(err.getMessage());
}
}
}
Tags:
作者:佚名评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论