Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I put my employeedetailxml into a folder named "res\raw". When I attempt to open it by specifying the file and folder name, I get the error "file not found".

How can I specify the path to my file?

I would much prefer to be able to pass 'R.raw.employeedetailxml' to FileInputStream to specify that it open that file. Is that possible? (I tried it, and got an error.)

Can FileInputStream take a Resource ID as parameter?

try{
   SAXParserFactory spf=SAXParserFactory.newInstance();
   SAXParser sp=spf.newSAXParser();
   XMLReader xr=sp.getXMLReader();

   EmployeeDetailHandler empDetailHandler=new EmployeeDetailHandler();
   xr.setContentHandler(empDetailHandler);

   xr.parse(new InputSource(new FileInputStream("\\res\\raw\\employeedetailxml.xml")));
}
share|improve this question

3 Answers

up vote 6 down vote accepted

Yes, you can use something similar to passing R.raw.employeedetailxml. You just need to fetch the resource XML file using that resource name, like so:

InputStream ins = getResources().openRawResource(R.raw.file_name);
share|improve this answer
Thank you It works fine – mahe madhi Oct 7 '11 at 6:24

this.getResources().openRawResource() returns an InputStream that will probably help you to parse the xml.

share|improve this answer

Try this:

InputStream inputStream =
    getResources().openRawResource(R.raw.employeedetailxml);
share|improve this answer
Thanks dude It works 100% – mahe madhi Oct 7 '11 at 6:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.