尝试检查内部存储中是否存在文件 [英] Trying to check if a file exists in internal storage
本文介绍了尝试检查内部存储中是否存在文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码是我如何确定内部存储中是否存在文件, MODE_PRIVATE
。
The following code is how I am trying to identify if a file exists in the internal storage, MODE_PRIVATE
.
public boolean isset(String filename){
FileInputStream fos = null;
try {
fos = openFileInput(filename);
//fos = openFileInput(getFilesDir()+"/"+filename);
if (fos != null) {
return true;
}else{
return false;
}
} catch (FileNotFoundException e) {
return false;
}
//File file=new File(mContext.getFilesDir(),filename);
//boolean exists = fos.exists();
}
然而,它进入异常并且不继续使用代码。它没有回报。为什么?
However, it goes into the exception and doesn't continue with the code. It doesn't do the return. Why?
推荐答案
希望这种方法可以帮到你。
hope this method helps you.
public boolean fileExist(String fname){
File file = getBaseContext().getFileStreamPath(fname);
return file.exists();
}
这篇关于尝试检查内部存储中是否存在文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文