Reputation: 63
I want to read an xml file placed in assets/ directory. I've tried this solution (finded online)
InputStream istr = context.getAssets().open("stanza.xml");
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xrp = factory.newPullParser();
xrp.setInput(istr, "UTF-8");
but return me FileNotFoundException, but the file exists.
Please, help me to understand.
Upvotes: 0
Views: 523
Reputation: 132992
use
InputStream istr = context.getResources().getAssets().open("<FILE_PATH/YOUR_FILE_NAME>");
instead of
InputStream istr = context.getAssets().open("stanza.xml");
Upvotes: 1
Reputation: 5336
if your code is of your activity you can simply write:
InputStream istr = getResources().getAssets().open("stanza.xml");
Upvotes: 1