Load file from resource

android

Solution

This question is tagged as "Android" and I noticed that you mentioned an `Activity`, so I'm going to assume that you're trying to load an XML file within an Android application. If that is the case, put your XML file under `/assets` and call:

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

from your `Activity`. From there, you can manipulate it into `SAXBuilder`. This will only work if you've set up your test to run on the emulator (or if you're just trying to debug outside of a unit test).

Problem

To sum up: in order to add easily unit tests for a SAX parser I would like to load XML from a file. Now, I have my XML in a static string inside my unit test class, but it is not very convenient for large XML. This is why I would like to add some XML files to my project and load them in my unit test. How can I do this?

Original source