标签:生成 class log pen date end new make stringbu
public void click(View view) { StringBuffer sb = new StringBuffer(); sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); sb.append("<SMSS>"); for (SMSbean list : mLists) { sb.append("<SMS>"); sb.append("<address>"); sb.append(list.getAddress()); sb.append("</address>"); sb.append("<body>"); sb.append(list.getBody()); sb.append("</body>"); sb.append("<date>"); sb.append(list.getDate()); sb.append("</date>"); sb.append("</SMS>"); } sb.append("<SMSS>"); try { String s = sb.toString(); // Log.d(TAG, "click: "+s); String path = Environment.getExternalStorageDirectory().getAbsolutePath(); Log.d(TAG, "click: " + path); File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "Config.xml"); FileOutputStream fos = new FileOutputStream(file); fos.write(s.getBytes()); fos.close(); Toast.makeText(this, "保存成功", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(this, "保存失败", Toast.LENGTH_SHORT).show(); } }
public void click1(View view) { try { XmlSerializer serializer = Xml.newSerializer(); File file = new File(getFilesDir().getPath(), "ConfigCopy.xml"); String path = getFilesDir().getPath(); Log.d(TAG, "click1: " + path); FileOutputStream fos = new FileOutputStream(file); serializer.setOutput(fos, "utf-8"); serializer.startDocument("utf-8", true); serializer.startTag(null, "smss"); for (int i = 0; i < mLists.size(); i++) { serializer.startTag(null, "sms"); serializer.startTag(null, "address"); serializer.text(mLists.get(i).getAddress()); serializer.endTag(null, "address"); serializer.startTag(null, "body"); serializer.text(mLists.get(i).getBody()); serializer.endTag(null, "body"); serializer.startTag(null, "date"); serializer.text(mLists.get(i).getDate()); serializer.endTag(null, "date"); serializer.endTag(null, "sms"); } serializer.endTag(null, "smss"); serializer.endDocument(); fos.close(); Toast.makeText(this, "保存成功", Toast.LENGTH_SHORT).show(); } catch (IOException e) { e.printStackTrace(); Toast.makeText(this, "保存失败", Toast.LENGTH_SHORT).show(); } }
标签:生成 class log pen date end new make stringbu
原文地址:https://www.cnblogs.com/nangongyibin/p/10200050.html