2014-03-05 82 views
0

我正在從事需要從單個超鏈接下載多個文件的任務。當我調用一個API鏈接時,我希望它返回多個文件。如何從單個超鏈接下載多個文件

我當前的代碼只下載一個文件:

try { 
    URL url = new URL(f_url[0]); 
    URLConnection conection = url.openConnection(); 
    conection.connect(); 
    // getting file length 
    int lenghtOfFile = conection.getContentLength(); 

    // input stream to read file - with 8k buffer 
    InputStream input = new BufferedInputStream(url.openStream(), 8192); 

    // Output stream to write file 
    OutputStream output = new FileOutputStream("/sdcard/downloadedfile.jpg"); 

    byte data[] = new byte[1024]; 

    long total = 0; 

    while ((count = input.read(data)) != -1) { 
     total += count; 
     // publishing the progress.... 
     // After this onProgressUpdate will be called 
     publishProgress(""+(int)((total*100)/lenghtOfFile)); 

     // writing data to file 
     output.write(data, 0, count); 
    } 

    // flushing output 
    output.flush(); 

    // closing streams 
    output.close(); 
    input.close(); 

} catch (Exception e) { 
    Log.e("Error: ", e.getMessage()); 
} 
+1

我不熟悉任何HTTP協議,它允許您在一個響應中發送多個文件,除非它們被壓縮。我很好奇,服務器響應是什麼樣的? – 323go

+0

@ 323go這將返回流對象/文件的多個列表 – android

+0

它遵循什麼標準? – 323go

回答

0

檢查這個site。它下載多個文件並在屏幕上顯示其內容

相關問題