문제

I have an xml file under res folder, the structure is res/raw/myfile.xml. Now i am using JDOM for parsing the file using SAXBuilder.build("raw/myfile.xml"); And in Logcat it is showing that it cannot open the file. How can I achieve this? any suggestions?

도움이 되었습니까?

해결책

This is how you parse a raw resource called myfile.xml:

InputStream input = context.getResources().openRawResource(com.YourApp.R.raw.myfile);
Document doc = DocumentBuilder.parse(input);

Note1 Notice that there is no file extension at the end of com.YourApp.R.raw.myfile! (so you cannot have two different files with same name)
Note2 You cannot make sub folders under raw folder!
Note3 If I remeber correctly, your file name should have all lower case and no spaces!

다른 팁

Maybe this'll help:

Referring to Android Resources Using URIs

As soon as you've built your URI you can easily get the path as a string and pass it to the parser. See URI documentation (method getPath)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top