以下代码是我尝试识别内部存储文件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();
}
但是,它会进入异常状态,并且不会继续执行代码。它不做返回。为什么?
最佳答案
希望这种方法对您有帮助。
public boolean fileExist(String fname){
File file = getBaseContext().getFileStreamPath(fname);
return file.exists();
}
关于java - 尝试检查内部存储中是否存在文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10576930/