Download file from resource

To summarize: to add simple unit tests for SAX parsing, I would like to load the XML from a file.

Now I have XML in a static string inside my unit test class, but this is not very convenient for large XML.

This is why I would like to add some XML files to my project and load them into my unit test. How can i do this?

+3
source share
2 answers

This question is marked as “Android,” and I noticed that you mentioned Activity, so I'm going to assume that you are trying to load an XML file in an Android application. If so, put your XML file under /assetsand call:

InputStream is = getAssets().open("input.xml")

Activity. SAXBuilder. , ( unit test).

+9

SAXBuilder :   ( java.io.File)           . http://www.jdom.org/docs/apidocs/org/jdom/input/SAXBuilder.html

+1

Source: https://habr.com/ru/post/1724805/


All Articles