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

前端之家收集整理的这篇文章主要介绍了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.f2er.com/android/318390.html

猜你在找的Android相关文章