且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查文件是否在目录中存在SD卡

更新时间:2022-10-14 23:31:05

 文件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.