Note that you need to set the SD card permissions here
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/54/6D/wKiom1SBwW-xDhQgAACasQh6_Cc145.jpg "title=" QQ picture 20141205223036.jpg "alt=" Wkiom1sbww-xdhqgaacasqh6_cc145.jpg "/>
public void OnClick (View arg0) {
Creating objects that serialize XML data
XmlSerializer Xml=xml.newserializer ();
Create a target file object
File file= new file (Environment.getexternalstoragedirectory (), "Stuinfo");
Creating a document output stream object
FileOutputStream Fos=null;
try {
FOS = new FileOutputStream (file);
Set the encoding set at output time
Xml.setoutput (FOS, "utf-8");
Setting the output document as a standalone XML
Xml.startdocument ("Utf-8", true);
Set Root start tag
Xml.starttag (NULL, "students");
Looping through the generation of student elements
for (int i=0;i<list_name.size (); i++)
{
Xml.starttag (NULL, "student");
Xml.starttag (NULL, "name");
Xml.text (List_name.get (i));
Xml.endtag (NULL, "name");
Xml.starttag (null, "sex");
Xml.text (List_sex.get (i));
Xml.endtag (null, "sex");
Xml.starttag (NULL, "age");
Xml.text (List_age.get (i));
Xml.endtag (NULL, "age");
Xml.starttag (NULL, "tel");
Xml.text (List_tel.get (i));
Xml.endtag (NULL, "tel");
Xml.endtag (NULL, "student");
}
Set Root end tag
Xml.endtag (NULL, "students");
Set document End
Xml.enddocument ();
Freeing resources
Fos.close ();
Toast.maketext (Mainactivity.this, "Save succeeded", "the"). Show ();
} catch (Exception e) {
Toast.maketext (Mainactivity.this, "Save Failed", +). Show ();
}
}
});
This article is from the "Android Development 0 Foundation" blog, please make sure to keep this source http://jinchao.blog.51cto.com/9651275/1586803
How Android generates XML file data