黑马程序员技术交流社区
标题:
android生成xml文件
[打印本页]
作者:
冯超
时间:
2013-8-25 15:24
标题:
android生成xml文件
public void back_Sms(View v) throws IOException {
StringBuilder sb = new StringBuilder();
XmlSerializer xml = Xml.newSerializer();
boolean judge_sd = true;
File file;
FileOutputStream fos;
if(Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
file = new File(Environment.getExternalStorageDirectory(), "info.xml");
fos = new FileOutputStream(file);
xml.setOutput(fos, "utf-8");
}
else {
file = new File(this.getFilesDir(), "info.xml");
fos = new FileOutputStream(file);
xml.setOutput(fos, "utf-8");
judge_sd = false;
}
xml.startDocument("utf-8", true);
xml.startTag(null, "Smss");
for(Sms s : sms) {
xml.startTag(null, "sms");
xml.startTag(null, "name");
xml.text(s.getName());
xml.endTag(null, "name");
xml.startTag(null, "context");
xml.text(s.getContext());
xml.endTag(null, "context");
xml.startTag(null, "number");
xml.text(s.getNumber());
xml.endTag(null, "number");
xml.endTag(null, "sms");
}
xml.endTag(null, "Smss");
xml.endDocument();
fos.close();
if(judge_sd)
Toast.makeText(this, "备份SD卡成功", 0).show();
else
Toast.makeText(this, "备份手机内存卡成功", 0).show();
}
复制代码
作者:
黄兴旺
时间:
2013-8-25 16:11
亲 辛苦了。。
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2