package httpdown.org.jasen;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
public class DownloadTest {
publicstatic void main(String[] args) {
try {
File file = new File("test.apk");
HttpURLConnection connection = (HttpURLConnection) newURL("http://skycnxz2.wy119.com/4/wandoujia.apk.apk").openConnection();
connection.setRequestMethod("GET");
long sum = 0 ;
if(file.exists()){
sum = file.length();
connection.setRequestProperty("Range","bytes="+file.length()+"-");
}
int code = connection.getResponseCode();
int contentLength = connection.getContentLength();
contentLength += sum;
if (code == 200 || code == 206) {
InputStream is = connection.getInputStream();
FileOutputStream fos = new FileOutputStream(file, true);
byte[] buffer = new byte[102400];
int length = 0 ;
long startTime = System.currentTimeMillis();
while ((length = is.read(buffer)) != -1) {