//1、声明URL
String path="http://localhost:8080/day22_DownLoad/file/a.rmvb";
URL url=new URL(path);
//2、设置已下载文件
String savePath="d:\\a.rmvb";
File file=new File(savePath);
long size=file.length();//文件当前大小,刚开始时返回0
System.out.println(size);
//3、设置连接
HttpURLConnection conn= (HttpURLConnection) url.openConnection();
//4、设置访问类型
conn.setRequestMethod("GET");
//5、设置下载区间
conn.setRequestProperty("range","bytes="+size+"-");
conn.connect();
//6、状态码
int code=conn.getResponseCode();//断点是206
if(code==206)
{
InputStream in=conn.getInputStream();
int serviceSize=conn.getContentLength();
//必须使用
RandomAccessFile out=new RandomAccessFile(file, "rw");
//从size字节开始写
out.seek(size);
byte[] b=new byte[1024];
int len=-1;
while((len=in.read(b))!=-1)
{
out.write(b,0,len);
}
out.close();
}