我在xml
文件夹下的res文件夹中有一个xml
文件。我需要检查这个文件是否存在。我使用getidentifier
检查存在但是我收到了错误。
如图所示。如果checkExistence = 1(如果文件存在),我有一个名为checkExistence的整数。但是应用程序不起作用。可能导致这种情况的原因是什么?
答案 0 :(得分:0)
最后我解决了这个问题..我所做的是:
Context context=this;
int checkExistence;
...
...
...
final String resourcename= String.valueOf(R.xml.xmlfiletocheck);
checkExistence = context.getResources().getIdentifier(resourcename,"xml",context.getPackageName());
...
...
if(checkExistence!=0) {
//if number is different than 0, it means file exists
..
..
}