易采站长站为您分析Android实现多线程下载文件的方法,以实例形式较为详细的分析了Android多线程文件传输及合并等操作的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了Android实现多线程下载文件的方法。。具体如下:
多线程下载大概思路就是通过Range 属性实现文件分段,然后用RandomAccessFile 来读写文件,最终合并为一个文件
首先看下效果图:

创建工程 ThreadDemo
首先布局文件 threaddemo.xml
- <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://www.easck.com/apk/res/android"
- android:orientation="vertical" android:layout_width="fill_parent"
- android:layout_height="fill_parent" >
- <TextView android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:text="下载地址"
- /> <TextView
- android:id="@+id/downloadurl" android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:lines="5"
- /> <TextView
- android:layout_width="fill_parent" android:layout_height="wrap_content"
- android:text="线程数" />
- <EditText android:id="@+id/downloadnum"
- android:layout_width="fill_parent" android:layout_height="wrap_content"
- /> <ProgressBar
- android:id="@+id/downloadProgressBar" android:layout_width="fill_parent"
- style="?android:attr/progressBarStyleHorizontal" android:layout_height="wrap_content"
- /> <TextView
- android:id="@+id/downloadinfo" android:layout_width="fill_parent"
- android:layout_height="wrap_content" android:text="下载进度 0"










