微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Android – 从服务器上的文件夹下载所有文件

希望我能够正确解释这个……
我能够连接到我的Web服务器并下载单个文件.我现在尝试做的是连接到我的服务器并从特定文件夹下载所有苍蝇.在这种情况下,我想下载图像.
这是我用来下载单个文件代码……
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,count);
            }
            is.close();
            fos.close();

如何添加代码以使其从该文件夹下载所有文件

解决方法

我建议你在服务器端有一个脚本,它首先列出文件夹中的所有文件,然后你的应用程序逐个下载每个文件.

原文地址:https://www.jb51.cc/android/318390.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐