- 浏览: 392893 次
- 性别:
- 来自: 昆明
文章分类
- 全部博客 (198)
- java (28)
- J2EE (19)
- struts (33)
- sping (13)
- hibernate (18)
- mybatis (15)
- connection pool (3)
- DB (26)
- SQL (21)
- html (13)
- js (7)
- json (3)
- jquery (2)
- document (17)
- linux (15)
- C# (1)
- url (2)
- eweb4j (1)
- Turbine (1)
- 框架 (11)
- jdbcTemplate (3)
- aop (2)
- windows (2)
- ubuntu (1)
- eclipse (11)
- JPA (8)
- svn (4)
- get 传值 (2)
- mysql (5)
- oracle (2)
- hadoop (1)
- MongoDB (2)
- spring (1)
- python (1)
最新评论
-
jcbingjc:
楼主,你好,按照上面的配置,我报如下错误:Missing Pe ...
[properJavaRDP]在网页中实现远程连接 -
sucful:
折腾了半天跑不通 ,要传就搞个完整的吧
Struts2 <sx:div/>实现页面模块异步刷新 -
Kattou:
你好! 看了你写的这个分页 感觉很好, 但是不怎么会用么,请指 ...
jsp分页控件 -
我叫PSB:
地址完全用不了
eclipse中的安装 jseclipse -
1111emotion:
我的工程里还是有乱码的情况,我该改的地方都改了。
Eclipse/MyEclipse更改默认字符集 设置UTF-8
package run; import java.io.*; import java.net.*; import java.util.*; // This class downloads a file from a URL. class Download extends Observable implements Runnable { // Max size of download buffer. private static final int MAX_BUFFER_SIZE = 1024; // These are the status names. public static final String STATUSES[] = {"Downloading", "Paused", "Complete", "Cancelled", "Error"}; // These are the status codes. public static final int DOWNLOADING = 0; public static final int PAUSED = 1; public static final int COMPLETE = 2; public static final int CANCELLED = 3; public static final int ERROR = 4; private URL url; // download URL private int size; // size of download in bytes private int downloaded; // number of bytes downloaded private int status; // current status of download // Constructor for Download. public Download(URL url) { this.url = url; size = -1; downloaded = 0; status = DOWNLOADING; // Begin the download. download(); } // Get this download's URL. public String getUrl() { return url.toString(); } // Get this download's size. public int getSize() { return size; } // Get this download's progress. public float getProgress() { return ((float) downloaded / size) * 100; } // Get this download's status. public int getStatus() { return status; } // Pause this download. public void pause() { status = PAUSED; stateChanged(); } // Resume this download. public void resume() { status = DOWNLOADING; stateChanged(); download(); } // Cancel this download. public void cancel() { status = CANCELLED; stateChanged(); } // Mark this download as having an error. private void error() { status = ERROR; stateChanged(); } // Start or resume downloading. private void download() { Thread thread = new Thread(this); thread.start(); } // Get file name portion of URL. private String getFileName(URL url) { String fileName = url.getFile(); return fileName.substring(fileName.lastIndexOf('/') + 1); } // Download file. public void run() { RandomAccessFile file = null; InputStream stream = null; try { // Open connection to URL. HttpURLConnection connection = (HttpURLConnection) url.openConnection(); // Specify what portion of file to download. connection.setRequestProperty("Range", "bytes=" + downloaded + "-"); // Connect to server. connection.connect(); // Make sure response code is in the 200 range. if (connection.getResponseCode() / 100 != 2) { error(); } // Check for valid content length. int contentLength = connection.getContentLength(); if (contentLength < 1) { error(); } // Set the size for this download if it hasn't been already set. if (size == -1) { size = contentLength; stateChanged(); } // Open file and seek to the end of it. file = new RandomAccessFile("/home/zf/" + getFileName(url), "rw"); System.out.println(getFileName(url)); file.seek(downloaded); // RandomAccessFile loadFile = new RandomAccessFile("/home/zf/1", "rw"); stream = connection.getInputStream(); while (status == DOWNLOADING) { // Size buffer according to how much of the file is left to download. byte buffer[]; if (size - downloaded > MAX_BUFFER_SIZE) { buffer = new byte[MAX_BUFFER_SIZE]; } else { buffer = new byte[size - downloaded]; } // Read from server into buffer. int read = stream.read(buffer); if (read == -1) { break; } // Write buffer to file. file.write(buffer, 0, read); downloaded += read; stateChanged(); } // Change status to complete if this point was reached because downloading has finished. if (status == DOWNLOADING) { status = COMPLETE; stateChanged(); } } catch (Exception e) { error(); } finally { // Close file. if (file != null) { try { file.close(); } catch (Exception e) { } } // Close connection to server. if (stream != null) { try { stream.close(); } catch (Exception e) { } } } } // Notify observers that this download's status has changed. private void stateChanged() { setChanged(); notifyObservers(); } public static void main(String args[]) { try { Download d = new Download(new URL("http://www.oschina.net/img/logo.gif")); // d.run(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
发表评论
-
[properJavaRDP]在网页中实现远程连接
2017-07-19 16:21 1607内容摘要: 利用开源软件properJavaRDP实现远 ... -
Java 利用FTP上传,下载文件,遍历文件目录
2017-06-12 21:32 1495Java实现FTP上传下载文件的工具包有很多,这里我采用J ... -
用javacsv API 来操作csv文件
2017-06-08 16:04 794简单的操作代码: /** ... -
Apache与Tomcat整合,配置及压缩
2017-03-07 10:16 7241、下载Apache2和对应的mod_jk.so,m ... -
Ubuntu16安装JDK1.8与配置环境变量
2016-12-25 13:42 10801、源码包准备: 首先到官网下载jdk,http://w ... -
quartz 时间配置规则
2016-05-28 02:19 0quartz 时间配置规则 格式: [秒] [分] [小时 ... -
J2EE RMI搭建
2012-10-08 13:21 1691RMI接口: package com.ynitil.sinf ... -
struts2 url传值中文乱码解决方案
2012-09-21 16:21 1391HttpServletRequest request = Ac ... -
Java操作Excel方法详解
2012-07-03 16:15 1232JAVA 通常有两种方法来 ... -
JSP的九个隐含对象,EL表达式中的11个隐含对象,JSP的6个基本动作
2012-07-03 09:37 1574一、page 对象 page对 ... -
Java 7 的新特性一览表
2012-06-29 00:25 1220官方说是 7月28日 正式发布 Java 7 ,正常的话我们应 ... -
Java 7新功能介绍及与Java1.7性能测试比较
2012-06-29 00:20 2616这里将进行Java 7新功 ... -
把证书导入java的cacerts证书库
2012-05-30 09:49 1572把证书导入java的cacerts证书库的步骤: 第一步:I ... -
java去除html格式,提取文字信息
2012-05-25 11:13 11112import java.util.regex.Matcher; ... -
java.lang.OutOfMemoryError: Java heap space 解决方法
2012-04-09 11:12 1002java.lang.OutOfMemoryError: Jav ... -
JAVA导出Excel
2012-03-28 10:58 1527package lee; import java.io. ... -
HTMLParser抓取网页信息
2011-12-07 09:19 1898HTMLParser具有小巧,快速 ... -
Java基础 你掌握多少(转)
2011-11-26 00:15 1171一:1:简述Java的基本历史2:简单写出Java特点 ... -
面向对象设计的SOLID原则
2011-11-26 00:15 1159S.O.L.I.D是面向对象设计和编程(OOD& ... -
JAVA字符串转日期或日期转字符串(转)
2011-11-09 21:18 11593JAVA字符串转日期或日期转字符串(转) 定义了 ...
相关推荐
Eclipse下完整的java程序,包含HttpClient的全部jar包。通过java类文件,实现通过链接将文件下载本地
用ajax实现的java文件打包下载。可以输入扩展名选择文件下载。
Java实现HTTP文件下载
java使用itext实现pdf文件下载小案例,通过系统路径下载,和通过浏览器下载
主要介绍了JAVA通过HttpURLConnection 上传和下载文件的方法,非常具有实用价值,需要的朋友可以参考下
Java API文档通常包含在Java开发工具包(JDK)中,并可以通过Java编译器和Java虚拟机(JVM)使用。 Java API文档通常是通过Java开发工具包(JDK)中的文档生成器自动生成的。在JDK中,有一个命令行工具javadoc,可以通过...
通过java代码实现http下载文件,代码中有实例可供参考。
java访问https网址下载文件,当网页需要下载证书的时候,代码和操作步骤齐全。
主要为大家详细介绍了java后台批量下载文件并压缩成zip下载的方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
前端vue,后端java。 如果前端是其他语言,可自行转换。 实现在浏览器前端点击后的文件下载。 不是整个工程代码,只把涉及到下载用的前端的代码和后端的代码贴出来了,可以直接复制使用,有详细的步骤。 包含了前端...
使用流下载文件。java response 下载文件方法。
利用java图形化界面和网络编程相结合实现的--文件上传。 运行步骤: (1)分别运行工程两个包中的两个.java文件(UploadClient.java和UploadServer.java)分别会弹出“上传客服端”和“上传服务器”两个窗口。 ...
JAVA通过SMB的方式下载、上传远程Linux服务器的文件
java文件下载的几种方式
java通过ftp三种方式 上传 下载文件: 1. 通过sun :sun.net.ftp.FtpClient 2. 通过apache:org.apache.commons.net.ftp.FTPClient 3. 通过edtftp: com.enterprisedt.net.ftp.FileTransferClient
简单的文件下载 Java写法 简单的文件下载 Java写法 简单的文件下载 Java写法 简单的文件下载 Java写法 简单的文件下载 Java写法 简单的文件下载 Java写法
Java实现文件下载功能,以WORD文档方式展现给用户看。
java文件上传jjjava文件上传下载ava文件上传下载ava文件上传下载下载
java 通过http协议的url下载文件
可直接使用 下载 资源路径resources中的文件,直接下载直接使用