Download multiple concurrent files

April 15, 2018, at 9:45 PM

I need download multiple files (About 100 files)

It does not matter whether the download is synchronized

And just it is important that all files be downloaded.

My code java for get name files and urls:

for (int i = 0; i < AssetData.size(); i++){
        String item = AssetData.get(i).toString();
        String name[] = item.split("/");
        String Url = setting.Main_Domain+"/"+item;// Url for downloading
        String fname =name[name.length-1] ;// File name like: test.txt
        File file2 =  new File(getFilesDir(),item.replace(fname,"")); // Parent File like: data/user/0/

The size of the files is small and all together is about 3 megabytes

Answer 1

You can implement your code with using this library. You can download multiple files concurrent or you can start next download after one is completed.

This is how your code will look

int downloadId =, dirPath, fileName)
                        .setOnStartOrResumeListener(new OnStartOrResumeListener() {
                            public void onStartOrResume() {
                        .setOnPauseListener(new OnPauseListener() {
                            public void onPause() {
                        .setOnCancelListener(new OnCancelListener() {
                            public void onCancel() {
                        .setOnProgressListener(new OnProgressListener() {
                            public void onProgress(Progress progress) {
                        .start(new OnDownloadListener() {
                            public void onDownloadComplete() {
                            public void onError(Error error) {

Isn't this simple. :)

Answer 2

Keep track and follow the best practises, I recommand to learn and use RxJava and Retrofit2 to download your files, rxjava will take care about asynchronous tasks and retrofit will simplify downloading the concrete files, check this answer Download and write a file with Retrofit and RxJava

Rent Charter Buses Company
Best language to learn JAVA or Node.js [on hold]

Best language to learn JAVA or Node.js [on hold]

Im looking at a couple of coding bootcampsNode

Type conversion for a String in an array throws &ldquo;Unknown Source Error&rdquo; in Java

Type conversion for a String in an array throws “Unknown Source Error” in Java

I am trying to parse a CSV file with java and get some ids

How would i know if Certain class&#39;s object creation would be expensive

How would i know if Certain class's object creation would be expensive

I assume If a thread unsafe class's object creation is expensive and we would like to use that instance at different place for thread execution in multi threaded environment, we should use ThreadLocalBecause it is expensive and it is unnecessary to create...