I'm trying to read the same file "xmlfile.xml" from the assets folder and also another copy from the SD card sdcard/download/.
I can Read from SD Card:
I can't not Read from Assets folder:
This code il NOT Working
File source = new File("file:///android_asset/xmlfile.xml");
boolean unfile = source.isFile();
boolean Esiste = source.exists();
try
{
// todo
} catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
This code il Working
File source = new File("/sdcard/" + "download" + "/" + "xmlfile.xml");
boolean unfile = source.isFile();
boolean Esiste = source.exists();
try
{
// todo
} catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
someone can explain me how can I read the file from the Assets folder.
thanks marco
We recommend XmlPullParser , which is an efficient and maintainable way to parse XML on Android. Historically Android has had two implementations of this interface: KXmlParser via XmlPullParserFactory.
Assets provide a way to add arbitrary files like text, XML, HTML, fonts, music, and video in the application. If one tries to add these files as “resources“, Android will treat them into its resource system and you will be unable to get the raw data.
Android DOM(Document Object Model) parser is a program that parses an XML document and extracts the required information from it. This parser uses an object-based approach for creating and parsing the XML files. In General, a DOM parser loads the XML file into the Android memory to parse the XML document.
To open an asset you'd need the following piece of code:
InputStream is = getAssets().open("xmlfile.xml")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With