Search code examples
androidinputstreamxmlpullparser

how to make InputStream for local xml file


I'm beginner android app developer.

I'm going to parse xml file saved in local storage.

But I don't have idea how to make InputStream.

Please tell me some advice. pre-Thanks!!

... APP_LOCAL_DIR = "/data/com.qqq.qqq/appname/"; 
String xml_file_path = APP_LOCAL_DIR.getAbsoluteFile() +"/" + YYYYMM + ".xml";

try {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setValidating(false);
        XmlPullParser myxml = factory.newPullParser(); 

        InputStream raw = ________________________???? 
        myxml.setInput(raw, null);

 ....... 

Solution

  • Your data is coming from a file, so you want to use a FileInputStream which extends InputStream:

    InputStream raw = new FileInputStream(new File(xml_file_path));