Android的 - 从服务器上的一个文件夹中下载的所有文件 [英] Android - Download all files from a folder on server

查看:488
本文介绍了Android的 - 从服务器上的一个文件夹中下载的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望我能够正确地解释这个... 我能够连接到我的Web服务器,并下载一个file.What我现在试图做的是连接到我的服务器,并从一个特定的folder.In下载所有的苍蝇这种情况下,我想下载图像。 这是codeI用于下载一个文件...

Hope I am able to explain this correctly... I am able to connect to my web server and download a single file.What I am now attempting to do is connect to my server and download all the flies from a particular folder.In this case i want to download images. This is the code i use to download a single file...

URL url  = new URL("http://127.0.0.1/Folder/file.csv");
            URLConnection conexion = url.openConnection();
            conexion.connect();
            int lenghtOfFile = conexion.getContentLength();
            InputStream is = url.openStream();
            File testDirectory = 
            new File(Environment.getExternalStorageDirectory()+"/Folder");
            if(!testDirectory.exists()){
                testDirectory.mkdir();
            }
            FileOutputStream fos = new FileOutputStream(testDirectory+"/file.csv");
            byte data[] = new byte[1024];
            int count = 0;
            long total = 0;
            int progress = 0;
            while ((count=is.read(data)) != -1){
                total += count;
                int progress_temp = (int)total*100/lenghtOfFile;
                if(progress_temp%10 == 0 && progress != progress_temp){
                    progress = progress_temp;
                }
                fos.write(data, 0, count);
            }
            is.close();
            fos.close();

如何添加到此code,使之从该文件夹下载的所有文件?

How can I add to this code to make it download all the files from that folder?

推荐答案

我会建议你有在服务器端,它首先给你所有的文件列表中文件夹内的脚本,然后将应用程序下载的每个文件中的一个由之一。

I would suggest you to have a script at server's end, which first gives you list of all the files inside a folder, and then your application downloads each file one by one.

这篇关于Android的 - 从服务器上的一个文件夹中下载的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆