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

I am trying to get an input stream from something like this.

InputSource myInputSource = new InputSource(activity.getResources().openRawResource(com.MYCLass.R.xml.programs)); myXMLReader.parse(myInputSource); 

and then call the parser in the instance of the parser i Created. Some like I get nothing. Works great if I use an XML server.

+4
source share
2 answers

Put the xml file in /res/raw folder . It seems that openRawResource only opens resources from this folder. You can also try getResources().getXml(com.MYCLass.R.xml.programs); which will return you an instance of the XML parser.

Part of the code taken from @Krupa

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

You can read the file with the following code:

 InputStream object = this.getResources() .openRawResource(R.rawFolderName.fileName); 
+4
source

All Articles