我正在处理一个android应用程序,我想将xml文件解析为本地资源。我用jdom解析它,但是我有一个问题,我无法打开文件,我不知道为什么。错误在这一行:无法在android上打开xml文件
document = builder.build(new File("res/xml/data.xml"));
该文件位于我的项目文件夹res/xml中。我得到这个错误:
java.io.IOException: Couldn't open file:/res/xml/data.xml
Caused by java.io.FileNotFoundException :res/xml/data.xml
我尝试这样做:
document = builder.build(new File("data.xml"));
,但没有奏效。我不知道为什么没有找到该文件。
你有想法吗?
在此先感谢
谢谢您的建议。 'Uri路径'有效但不行
document = builder.build(new File(path));
方法类文件必须具有类型entree字符串。我尝试这样做:
document = builder.build(new File(path.getPath());
但它返回null和
document = builder.build(new File(path.toString());
我得到了同样的错误。你有想法吗? 在此先感谢!