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

Check if a file exists in the android resources - Android

我正在尝试从 "android.resource://" + getPackageName() + "/raw/video" 获取一段视频,它读起来很完美。我如何检查该文件是否存在或丢失?

你可以这样检查。

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;
}