Java 断点续传
本文从http://www.blogjava.net/breezedancer/archive/2007/07/19/131264.html转载
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
//断点续传
public class Download {
public static void down(String URL, long nPos, String savePathAndFile) {
try {
URL url = new URL(URL);
HttpURLConnection httpConnection = (HttpURLConnection) url
.openConnection();
// 设置User-Agent
httpConnection.setRequestProperty("User-Agent", "NetFox");
// 设置断点续传的开始位置
httpConnection.setRequestProperty("RANGE", "bytes=" + nPos);
// 获得输入流
InputStream input = httpConnection.getInputStream();
RandomAccessFile oSavedFile = new RandomAccessFile(savePathAndFile,
"rw");
// 定位文件指针到nPos位置
oSavedFile.seek(nPos);
byte[] b = new byte[1024];
int nRead;
// 从输入流中读入字节流,然后写到文件中
while ((nRead = input.read(b, 0, 1024)) > 0) {
(oSavedFile).write(b, 0, nRead);
}
httpConnection.disconnect();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static long getRemoteFileSize(String url) {
long size = 0;
try {
HttpURLConnection conn = (HttpURLConnection) (new URL(url))
.openConnection();
size = conn.getContentLength();
conn.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
return size;
}
public static void main(String[] args) {
String url = "http://www.blogjava.net/bree
相关文档:
http://wsc830719.javaeye.com/blog/523873
http://topic.csdn.net/u/20100406/01/e8fa95e2-417d-4706-98a0-2288970697f2.html
http://javafoot.blog.hexun.com/3905915_d.html
http://wiki.apache.org/tapestry/HowToSetupEclipseWtp
在Eclipse下安装Tomcat插件
http://hi.baidu.com/tianlan133/blog/item/ad4c2699ea ......
在做pdf文档转成jpg的时候,发现了Jmagick的创建高质量的图片的一个java类库,自己以前使用另外的一个类库,感觉这个更好点,就试着用了下,感觉不错
1.使用的windows下的jmagick-win-6.3.9-Q16.zip 地址是:http://downloads.jmagick.org/6.3.9/
2.doc对应的api地址:http://downloads.jmagick.org/jmagick-doc/
3.安装Ima ......
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
/**
* @author dengshaohua
*/
public class ReadPhone {
/**
* 读取数据
*/
public void ReadData(){
try {
FileReader read = new File ......