以下代码是我试图识别内部存储中是否存在文件的方法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();
}
Run Code Online (Sandbox Code Playgroud)
但是,它进入异常并且不继续使用代码.它没有回报.为什么?
Has*_*y31 114
希望这种方法可以帮到你.
public boolean fileExist(String fname){
File file = getBaseContext().getFileStreamPath(fname);
return file.exists();
}
Run Code Online (Sandbox Code Playgroud)
对于内部存储,这对我有用:
public boolean isFilePresent(String fileName) {
String path = getContext().getFilesDir().getAbsolutePath() + "/" + fileName;
File file = new File(path);
return file.exists();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30548 次 |
| 最近记录: |