检查android资源中是否存在文件 - Android

时间:2017-10-31 04:14:57

标签: java android android-resources

我正在尝试从"android.resource://" + getPackageName() + "/raw/video"获取视频,并且它会完美地读取它。如何检查该文件是否存在或缺失?

1 个答案:

答案 0 :(得分:1)

你可以这样检查。

int checkExistence = mContext.getResources().getIdentifier("FILENAME_WITHOUT_EXTENSION", "raw", mContext.getPackageName());

if ( checkExistence != 0 ) {  // the resouce exists...
result = true;
}
else {  // checkExistence == 0  // the resouce does NOT exist!!
result = false;
}
相关问题