如何读取本地XML文件是资源文件夹作为Android的一个输入流? [英] How to read local xml file is resource folder as a input stream in android?
问题描述
我想从这样的事情让输入流。
I am trying to get input stream from something like this.
InputSource myInputSource = new InputSource(activity.getResources().openRawResource(com.MYCLass.R.xml.programs));
myXMLReader.parse(myInputSource);
,然后调用解析的解析器实例我创建。一些如何,我什么也得不到。
如果我使用一台服务器的XML做工精细....
and then call parse on the parser instance i Created. Some how i get nothing.
Works fine if I use a server XML....
推荐答案
把XML文件放到 / RES /原始文件夹
。它看起来像<一个href="http://developer.android.com/reference/android/content/res/Resources.html#openRawResource%28int%29"相对=nofollow> openRawResource 只从该文件夹打开资源。您也可以尝试 getResources()的getXML(com.MYCLass.R.xml.programs);
这会回报你的XML解析器的一个实例
Put the xml file into /res/raw folder
. It looks like openRawResource opens resources from that folder only. You can also try getResources().getXml(com.MYCLass.R.xml.programs);
which will return you an instance of XML parser.
一块code从@Krupa采取
A piece of code taken from @Krupa
InputStream object = this.getResources()
.openRawResource(R.raw.fileName);
这篇关于如何读取本地XML文件是资源文件夹作为Android的一个输入流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!