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();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With