簡體   English   中英

讀取資產Xml文件

[英]Reading Asset Xml File

我想讀取置於assets /目錄中的xml文件。 我試過這個解決方案(在線查找)

InputStream istr = context.getAssets().open("stanza.xml");
XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); 
factory.setNamespaceAware(true); 
XmlPullParser xrp = factory.newPullParser(); 
xrp.setInput(istr, "UTF-8");

但是返回FileNotFoundException,但該文件存在。

請幫我理解。

采用

InputStream istr = context.getResources().getAssets().open("<FILE_PATH/YOUR_FILE_NAME>"); 

代替

InputStream istr = context.getAssets().open("stanza.xml");

如果您的代碼屬於您的活動,您可以簡單地寫:

InputStream istr =  getResources().getAssets().open("stanza.xml"); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM