HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(url);
HttpResponse response;
String startPosition ="bytes="+CurSize+"-";//下载起始位置。
get.addHeader("Range",startPosition);
response = client.execute(get);
HttpEntity entity = response.getEntity();
long length = entity.getContentLength();//以上为网络连接
InputStream In = entity.getContent();
FileOutputStream fileOutputStream = null;
fileOutputStream = new FileOutputStream(file);
byte[] buf = new byte[1024];
int ch = Integer.parseInt(startPosition)//下载起始点,不是从0开始。
int count = 0;
while (((ch = In.read(buf)) != -1)&&!cancelUpdate&&hasEnoughMemory()){
fileOutputStream.write(buf, 0, ch);
count += ch;
pBar.setProgress((int) ((float)count/length*100));
if (length > 0) {}
}
还是只能使用RandomAccessFile?
HttpClient client = new DefaultHttpClient();
HttpGet get = new HttpGet(url);
HttpResponse response;
String startPosition ="bytes="+CurSize+"-";//下载起始位置。
get.addHeader("Range",startPosition);
response = client.execute(get);
HttpEntity entity = response.getEntity();
long length = entity.getContentLength();//以上为网络连接
InputStream In = entity.getContent();
FileOutputStream fileOutputStream = null;
fileOutputStream = new FileOutputStream(file);
byte[] buf = new byte[1024];
int ch = Integer.parseInt(startPosition)//下载起始点,不是从0开始。
int count = 0;
while (((ch = In.read(buf)) != -1)&&!cancelUpdate&&hasEnoughMemory()){
fileOutputStream.write(buf, 0, ch);
count += ch;
pBar.setProgress((int) ((float)count/length*100));
if (length > 0) {}
}