本文介绍了如何检查文件是否在目录中存在SD卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要检查给定文件是否在android的SD卡存在。我使用绝对路径创建文件和 file.exists()
,但它不工作检查尝试它。该文件的URL是文件:///mnt/sdcard/book1/page2.html
和文件确实存在。但不知何故, file.exists()
没有显示一样的。
解决方案
文件extStore = Environment.getExternalStorageDirectory();
myfile文件=新的文件(extStore.getAbsolutePath()+/book1/page2.html);如果(myFile.exists()){
...
}
这应该工作。
I want to check whether a given file exists in android sd card. I am trying it out with creating a file using the absolute path and checking with file.exists()
but its not working. The URL for the file is "file:///mnt/sdcard/book1/page2.html"
and the file does exist. But somehow file.exists()
isn't showing the same.
解决方案
File extStore = Environment.getExternalStorageDirectory();
File myFile = new File(extStore.getAbsolutePath() + "/book1/page2.html");
if(myFile.exists()){
...
}
This should work.
这篇关于如何检查文件是否在目录中存在SD卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!