简体   繁体   English

如何从单个超链接下载多个文件

[英]How to download multiple files from a single hyperlink

I am working on a task where I need to download multiple files from a single hyperlink. 我正在执行一项需要从单个超链接下载多个文件的任务。 When I call the one API link I want it to return multiple files. 当我调用一个API链接时,我希望它返回多个文件。

My current code is only downloading a single file: 我当前的代码仅下载一个文件:

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());
}

check this site . 检查这个网站 It downloads multiple files and shows its content on your screen 它会下载多个文件并在屏幕上显示其内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM