我在 res 文件夹下有一个 xml 文件,结构是 res/raw/myfile.xml。现在我使用 JDOM 使用 SAXBuilder.build("raw/myfile.xml"); 解析文件。在 Logcat 中显示它无法打开该文件。我怎样才能做到这一点?有什么建议么?
问问题
2085 次
2 回答
1
这是您解析名为的原始资源的方式myfile.xml
:
InputStream input = context.getResources().openRawResource(com.YourApp.R.raw.myfile);
Document doc = DocumentBuilder.parse(input);
注意 1com.YourApp.R.raw.myfile
注意!结尾没有文件扩展名 (所以你不能有两个同名的不同文件)
注2你不能在 raw 文件夹下创建子文件夹!
Note3如果我没记错的话,你的文件名应该全部小写并且没有空格!
于 2011-09-07T14:27:57.850 回答
0
于 2011-09-07T14:11:47.420 回答