如何成为Android开发高手
2010-08-31 00:43:00 来源:WEB开发网034
035private FileDownloader downloader;
036
037
038
039public DownloadThread(FileDownloader downloader, URL downUrl, RandomAccessFile saveFile, int block, int startPos, int threadId) {
040
041this.downUrl = downUrl;
042
043this.saveFile = saveFile;
044
045this.block = block;
046
047this.startPos = startPos;
048
049this.downloader = downloader;
050
051this.threadId = threadId;
052
053this.downLength = startPos - (block * (threadId - 1));
054
055}
056
057
058
059@Override
060
061public void run() {
062
063if(downLength < block){//未下载完成
064
065try {
066
067HttpURLConnection http = (HttpURLConnection) downUrl.openConnection();
068
069http.setRequestMethod("GET");
070
071http.setRequestProperty("Accept", "image/gif, image/jpeg, image/pjpeg, image/pjpeg, application/x-shockwave-flash, application/xaml+xml, application/vnd.ms-xpsdocument, application/x-ms-xbap, application/x-ms-application, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
072
073http.setRequestProperty("Accept-Language", "zh-CN");
074
075http.setRequestProperty("Referer", downUrl.toString());
076
077http.setRequestProperty("Charset", "UTF-8");
078
079http.setRequestProperty("Range", "bytes=" + this.startPos + "-");
080
081http.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");
更多精彩
赞助商链接