URL url = new URL(http://www.oschina.net/no-exist.zip);

HttpURLConnection httpConnection = (HttpURLConnection)url.openConnection();

//设置User-Agent
//设置断点续传的开始位置
//获得输入流
InputStream input = httpConnection.getInputStream();
/**
从输入流中取出的字节流就是no-exist.zip文件从2000070开始的字节流。
大家看,其实断点续传用Java实现起来还是很简单的吧。
接下来要做的事就是怎么保存获得的流到文件中去了。
(2)保存文件采用的方法
我采用的是IO包中的RandAccessFile类。操作相当简单,假设从2000070处开始保存文件,代码如下:
 
*/
 
 
long nPos = 2000070;
 
//定位文件指针到nPos位置
 
oSavedFile.seek(nPos);
 
byte[] b = new byte[1024];
 
int nRead;
 
//从输入流中读入字节流,然后写到文件中
 
> 0)
 
{
 
oSavedFile.write(b,0,nRead);
 
}

 

转自:http://www.oschina.net/code/snippet_54100_623

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-06
  • 2021-11-16
  • 2022-12-23
  • 2022-12-23
  • 2021-09-25
  • 2022-12-23
相关资源
相似解决方案