- package com.hmm.Range;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.HttpURLConnection;
- import java.net.URL;
- public class Range {
-
- public static void main(String[] args) throws IOException{
- URL url = new URL("http://localhost:80/news/a.txt");
- //建立连接
- HttpURLConnection conn = (HttpURLConnection)url.openConnection();
- //设置断点续传,续传5以后的
- conn.setRequestProperty("Range", "bytes=5-");
- InputStream in = conn.getInputStream();
- FileOutputStream out = new FileOutputStream("c:\\a.txt",true);
- int len = 0;
- byte[] buf = new byte[1024];
- while((len=in.read(buf))!=-1)
- {
- out.write(buf,0,len);
- }
- out.close();
- }
- }
复制代码
|