자바 정지점 전송 실현
package test;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
/* @className:TestDown.java
* @classDescription: java
* @author:jiangmianyue
* @createTime:2011-11-29
*/
public class TestDown {
public static void main(String[] args) {
URL url = null;
try {
url = new URL("http://172.16.1.33/newfile/e358beb5367341929614332e1a390dfb.apk");
} catch (MalformedURLException e) {
e.printStackTrace();
}
URLConnection httpConnection = null;
try {
//
httpConnection = url.openConnection();
} catch (IOException e) {
e.printStackTrace();
}
// ua
httpConnection.setRequestProperty("User-Agent","NetFox");
// 100k
httpConnection.setRequestProperty("RANGE","bytes=102400-");
//
InputStream input = null;
try {
input = httpConnection.getInputStream();
} catch (IOException e) {
e.printStackTrace();
}
//
RandomAccessFile oSavedFile = null;
try {
oSavedFile = new RandomAccessFile("d://down.apk","rw");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// 100K
long nPos = 102400;
// nPos
try {
//
oSavedFile.seek(nPos);
} catch (IOException e) {
e.printStackTrace();
}
byte[] b = new byte[1024];
int nRead;
// ,
try {
// int n =0;
while((nRead=input.read(b,0,1024)) > 0)
{
oSavedFile.write(b,0,nRead);
/**
* n 100
* if(100 == n){
* break;
* }
*/
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
//
private static void setHeader(URLConnection con) {
con.setRequestProperty("User-Agent", "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.3) Gecko/2008092510 Ubuntu/8.04 (hardy) Firefox/3.0.3");
con.setRequestProperty("Accept-Language", "en-us,en;q=0.7,zh-cn;q=0.3");
con.setRequestProperty("Accept-Encoding", "aa");
con.setRequestProperty("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
con.setRequestProperty("Keep-Alive", "300");
con.setRequestProperty("Connection", "keep-alive");
con.setRequestProperty("If-Modified-Since", "Fri, 02 Jan 2009 17:00:05 GMT");
con.setRequestProperty("If-None-Match", "\"1261d8-4290-df64d224\"");
con.setRequestProperty("Cache-Control", "max-age=0");
con.setRequestProperty("Referer", "http://www.dianping.com");
}
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Http 정지점정지점 다운로드 와 일반 모드 가 다른 것 은 정지점 다운로드 의 헤더 정보 에 속성 RANGE: bytes = 100000 - 여기 RANGE 대표 클 라 이언 트 가 그 위치 에서 다운로드 해 야 합 니 다. C...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.