[英]Check if file exists in internal directory
我正在檢查文件是否在目錄中存在。 如果沒有,它應該下載它。
File file = new File(mediadir, _name);
if(file.exists()) {
Log.i("FILE EXISTS", _name);
} else {
Log.i("DOWNLOAD", _name);
new Download().execute(context, name, "http://192.168.2.136:8080/rest/transfer/"+ linkid +"/"+ username +"/" + json_data.getString("ID"));
}
但是file.exists()總是如此
該文件不存在
我在file.exists()之前運行它
File mediadir = getDir("tvr", Context.MODE_PRIVATE);
if (mediadir.isDirectory()) {
String[] children = mediadir.list();
for (int i = 0; i < children.length; i++) {
new File(mediadir, children[i]).delete();
}
}
您是否嘗試過使用isFile()?
嘗試這個,
for (File f : myDir.listFiles()) {
//Do your stuf
String name = f.getName();
//Here you will get file you have already stored in directory.
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.