开发者

How to read local xml file is resource folder as a input stream in android?

开发者 https://www.devze.com 2023-01-11 00:17 出处:网络
I am trying to get input stream from something like this. InputSource myInputSource = new InputSource(activity.getResources().openRawResource开发者_运维技巧(com.MYCLass.R.xml.programs));

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);

and then call parse on the parser instance i Created. Some how i get nothing.

Works fine if I use a server 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.

A piece of code taken from @Krupa

InputStream object = this.getResources()
                     .openRawResource(R.raw.fileName);


You can read the file by the following code :

InputStream object = this.getResources()
        .openRawResource(R.rawFolderName.fileName);
0

精彩评论

暂无评论...
验证码 换一张
取 消