package Test;
import java.io.RandomAccessFile;
import java.io.File;
//import java.io.InputStream;
import java.io.DataInputStream;
import java.io.BufferedInputStream;
//import java.io.FileInputStream;
import java.net.HttpURLConnection;
//import java.net.ConnectException;
import java.net.URL;
import java.lang.Runnable;
import java.lang.Thread;
import java.util.Date;
public class TestUpDown implements Runnable {
private HttpURLConnection connection;// 存储连接
private int downsize = -1;// 下载文件大小,初始值为-1
private int downed = 0;// 文加已下载大小,初始值为0
private RandomAccessFile savefile;// 记录下载信息存储文件
private URL fileurl;// 记录要下载文件的地址
private DataInputStream fileStream;// 记录下载的数据流
public TestUpDown() {
try {
/* 开始创建下载的存储文件,并初始化值 */
File tempfileobject = new File("e:\\11.pdf");
if (!tempfileobject.exists()) {
/* 文件不存在则建立 */
tempfileobject.createNewFile();
}
savefile = new RandomAccessFile(tempfileobject, "rw");
/* 建立连接 */
fileurl = new URL(
"http://www.computerapplications.com.cn/CN/article/downloadArticleFile.do?attachType=PDF&id=11182");
connection = (HttpURLConnection) fileurl.openConnection();
connection.setRequestProperty("Range", "byte=" + this.downed + "-");
this.downsize = connection.getContentLength();
// System.out.println(connection.getContentLength());
new Thread(this).start();
} catch (Exception e) {
System.out.println(e.toString());
System.out.println("构建器错误");
System.exit(0);
}
}
public void run() {
/* 开始下载文件,以下测试非断点续传,下载的文件存在问题 */
try {
System.out.println("begin!");
Date begintime = new Date();
begintime.setTime(new Date().getTime());
byte[] filebyte;
int onecelen;
// System.out.println(this.connection.getInputStream().getClass().getName());
this.fileStream = new DataInputStream(new BufferedInputStream(
this.connection.getInputStream()));
System.out.println("size = " + this.downsize);
while (this.downsize != this.downed) {
if (this.downsize - this.downed > 262144) {// 设置为最大256KB的缓存
filebyte = new byte[262144];
onecelen = 262144;
} else {
filebyte = new byte[this.downsize - this.downed];
onecelen = this.downsize - this.downed;
}
onecelen = this.fileStream.read(filebyte, 0, onecelen);
this.savefile.write(filebyte, 0, onecelen);
this.downed += onecelen;
System.out.println(this.downed);
}
this.savefile.close();
System.out.println("end!");
System.out.println(begintime.getTime());
System.out.println(new Date().getTime());
System.out.println(begintime.getTime() - new Date().getTime());
} catch (Exception e) {
System.out.println(e.toString());
System.out.println("run()方法有问题!");
}
}
public static void main(String[] src) throws Exception {
new TestUpDown();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于ajax的日程表实例
共28个文件
jar:7个
java:5个
class:5个
4星 · 超过85%的资源 需积分: 3 13 下载量 60 浏览量
2011-02-15
21:06:33
上传
评论
收藏 1.26MB RAR 举报
温馨提示
基于ajax实现的一个日程表项目。后台数据库用的是MySQL,可实现日程的添加、删除、修改。
资源推荐
资源详情
资源评论
收起资源包目录
calendar.rar (28个子文件)
日程表
ajax.sql 888KB
ajax
.settings
org.eclipse.jdt.core.prefs 334B
src
Test
DownLoad.java 1KB
TestUpDown.java 3KB
ajax
db
DBUtils.java 2KB
aa.java 3KB
DownLoad.java 51B
.project 1KB
WebRoot
jquery.js 20KB
META-INF
MANIFEST.MF 39B
WEB-INF
web.xml 769B
classes
Test
DownLoad.class 2KB
TestUpDown.class 3KB
ajax
db
DownLoad.class 265B
DBUtils.class 2KB
aa.class 2KB
lib
jsontools-core-1.7.jar 138KB
jsonplugin-0.25.jar 37KB
commons-dbutils-1.3.jar 40KB
watij.jar 278KB
mysql-connector-java-5.0.5-bin.jar 501KB
json-lib-2.3-jdk15.jar 148KB
json_simple-1.1.jar 16KB
calendar.html 14KB
index.jsp 829B
calendar.jsp 6KB
.mymetadata 285B
.classpath 901B
.myeclipse
共 28 条
- 1
资源评论
- beiqinkeji2012-06-04版本太旧用不了
jadeSearch
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- BrushNet电商公司和摄影公司都在用的AI工作流
- 12_base.apk
- 520马上到了两款动态爱心表白HTML代码(附源码)李峋同款爱心,快送给你爱的她或(他)吧12 情侣纪念日代码.zip
- 电子设计竞赛的单相不间断电源设计
- cutcamera1715961370938.png
- 基于MATLAB的图像处理课程设计报告.doc
- tensorflow-gpu-2.6.0-cp38-cp38-manylinux2010-x86-64.whl
- mmexport1715960553858.png
- tensorflow-gpu-2.6.0-cp37-cp37m-manylinux2010-x86-64.whl
- 通过 .NET 应用程序中的源代码查找 SQL 注入
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功