JDK中http协议下载文件简单示例
来源:互联网 发布:中国联合网络通信公司 编辑:程序博客网 时间:2024/05/16 05:57
http协议下载文件代码:
- public class HttpDownload {
- private final int BUF_SIZE = 8096;
- private String strUrl = null;
- private String localFile = null;
- private String localDir = null;
- private URL url = null;
- private HttpURLConnection httpConn = null;
- private boolean debug = true;
- public HttpDownload() {
- }
- public HttpDownload(String url, String file, String dir) throws IOException {
- strUrl = url;
- localFile = file;
- localDir = dir;
- init();
- }
- private void init() throws IOException {
- url = new URL(strUrl);
- httpConn = (HttpURLConnection)url.openConnection();
- }
- public void download() throws IOException {
- BufferedInputStream bis = null;
- FileOutputStream fos = null;
- int size = 0;
- byte[] buf = new byte[BUF_SIZE];
- httpConn.connect();
- bis = new BufferedInputStream(httpConn.getInputStream());
- fos = new FileOutputStream(localDir + File.separator + localFile);
- if (debug) {
- System.out.println("retreiving the file");
- }
- System.out.println("starting download.");
- while((size = bis.read(buf)) != -1) {
- fos.write(buf, 0, size);
- }
- fos.close();
- bis.close();
- httpConn.disconnect();
- System.out.println("download finish.");
- }
-
- JDK中http协议下载文件简单示例
- HTTP协议文件下载
- 使用HTTP协议 下载文件
- C++ HTTP协议 下载文件
- 使用HTTP协议下载文件
- HTTP协议实现文件下载
- ftp下载文件 简单示例
- [VB.NET]通过http协议下载文件
- http协议 文件下载原理详解
- 文件下载原理详解 http协议
- http协议 文件下载原理详解
- http协议 文件下载原理详解
- Android 使用http协议下载文件
- http协议 文件下载原理详解
- Android文件下载使用Http协议
- VC使用HTTP协议下载文件
- java多线程下载http协议文件
- 文件下载原理详解 http协议
- 广度优先算法链表节点类
- 浮尘
- 送走朋友。。。
- Protel DXP2004 破解版下载
- Dreamweaver中sql注入式攻击的防范
- JDK中http协议下载文件简单示例
- ORACLE CHANGYONG
- 行走控制
- Cannot find message resources under key org.apache.struts.action.MESSAGE
- wait和notify实例
- PHP与SQL注入攻击
- 地图生成父类
- 在表中添加列
- SQL注入攻击零距离