[英]How to check for the existence of a file?
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();
}
我正在使用上面的代碼來檢查文件是否存在。 我已經檢查了一個文件,它可以正常工作,但是當我在有多個(100-200)圖像的應用程序中使用它時,無論是否存在,它總是開始下載文件。 有沒有比這更好的方法了?
首先檢查文件夾中有多少張圖片:-
File extStore = Environment.getExternalStorageDirectory();
File[] imageDirs = extStore.listFiles(filterForImageFolders);
在上面之后,您運行循環並檢查您的狀況:-
for(int i=0;i<list.length;i++)
{
// ur condition
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.