如何成为Android开发高手
2010-08-31 00:43:00 来源:WEB开发网454
455Log.i(TAG, msg);
456
457}
458
459
460
461public static void main(String[] args) {
462
463/* FileDownloader loader = new FileDownloader(context, "http://browse.babasport.com/ejb3/ActivePort.exe",
464
465new File("D:\androidsoft\test"), 2);
466
467loader.getFileSize();//得到文件总大小
468
469try {
470
471loader.download(new DownloadProgressListener(){
472
473public void onDownloadSize(int size) {
474
475print("已经下载:"+ size);
476
477}
478
479});
480
481} catch (Exception e) {
482
483e.printStackTrace();
484
485}*/
486
487}
488
489
490}
2) 下面的类是真正支持下载的线程类:
view sourceprint?001import java.io.InputStream;
002
003import java.io.RandomAccessFile;
004
005import java.net.HttpURLConnection;
006
007import java.net.URL;
008
009
010
011import android.util.Log;
012
013
014
015public class DownloadThread extends Thread {
016
017private static final String TAG = "DownloadThread";
018
019private RandomAccessFile saveFile;
020
021private URL downUrl;
022
023private int block;
024
025/* 下载开始位置 */
026
027private int threadId = -1;
028
029private int startPos;
030
031private int downLength;
032
033private boolean finish = false;
更多精彩
赞助商链接