Reputation: 2326
String extra=imagepath.get(i).toString();
String extra2=imageid.get(i).toString();
String path = "/mnt/sdcard/Android/data/com.example.webdata/files/Download/" + extra2 + ".jpg";
File f = new File(path);
if(f.exists())
{
//Toast.makeText(getApplicationContext(), "File already exists....",
// Toast.LENGTH_SHORT).show();
}
else
{
downloadfile();
}
I am using the above code to check if a file exists or not. I have checked it with one file and it works fine, but when I use it in my application where there are multiple (100-200) images it always starts downloading files whether they exist or not. Is there a better method than this?
Upvotes: 1
Views: 157
Reputation: 38409
First check how many images on folder:-
File extStore = Environment.getExternalStorageDirectory();
File[] imageDirs = extStore.listFiles(filterForImageFolders);
after above you run the loop and check u r condition:-
for(int i=0;i<list.length;i++)
{
// ur condition
}
Upvotes: 1