Xml序列化

  • xml序列化
    • 實現思路 通過程序生成一個xml文件來備份手機短信. 先獲取手機短信的內容 —>通過xml備份.
    • StringBuffer 代碼如下
    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();}}

?

?
    • 通過官方提供序列化類實現xml序列化(通過程序生成一個xml)
    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();}}

?

?

轉載于:https://www.cnblogs.com/nangongyibin/p/10200050.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/388722.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388722.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388722.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

java 添加用戶 數據庫,跟屌絲學DB2 第二課 建立數據庫以及添加用戶

在安裝DB2 之后&#xff0c;就可以在 DB2 環境中創建自己的數據庫。首先考慮數據庫應該使用哪個實例。實例(instance) 提供一個由數據庫管理配置(DBM CFG)文件控制的邏輯層&#xff0c;可以在這里將多個數據庫分組在一起。DBM CFG 文件包含一組 DBM CFG 參數&#xff0c;可以使…

iphone視頻教程

公開課介紹 本課程共28集 翻譯至第15集 網易正在翻譯16-28集 敬請關注 返回公開課首頁 一鍵分享&#xff1a;  網易微博開心網豆瓣網新浪微博搜狐微博騰訊微博郵件 講師介紹 名稱&#xff1a;Alan Cannistraro 課程介紹 如果你對iPhone Development有興趣&#xff0c;以下是入…

在Python中有效使用JSON的4個技巧

Python has two data types that, together, form the perfect tool for working with JSON: dictionaries and lists. Lets explore how to:Python有兩種數據類型&#xff0c;它們一起構成了使用JSON的理想工具&#xff1a; 字典和列表 。 讓我們探索如何&#xff1a; load a…

Vlan中Trunk接口配置

Vlan中Trunk接口配置 參考文獻&#xff1a;HCNA網絡技術實驗指南 模擬器&#xff1a;eNSP 實驗環境&#xff1a; 實驗目的&#xff1a;掌握Trunk端口配置 掌握Trunk端口允許所有Vlan配置方法 掌握Trunk端口允許特定Vlan配置方法 實驗拓撲&#xff1a; 實驗IP地址 &#xff1a;…

django中的admin組件

Admin簡介&#xff1a; Admin:是django的后臺 管理的wed版本 我們現在models.py文件里面建幾張表&#xff1a; class Author(models.Model):nid models.AutoField(primary_keyTrue)namemodels.CharField( max_length32)agemodels.IntegerField()# 與AuthorDetail建立一對一的關…

虛擬主機創建虛擬lan_創建虛擬背景應用

虛擬主機創建虛擬lanThis is the Part 2 of the MediaPipe Series I am writing.這是我正在編寫的MediaPipe系列的第2部分。 Previously, we saw how to get started with MediaPipe and use it with your own tflite model. If you haven’t read it yet, check it out here.…

.net程序員安全注意代碼及服務器配置

概述 本人.net架構師&#xff0c;軟件行業為金融資訊以及股票交易類的軟件產品設計開發。由于長時間被黑客攻擊以及騷擾。從事高量客戶訪問的服務器解決架構設計以及程序員編寫指導工作。特此總結一些.net程序員在代碼編寫安全以及服務器設置安全常用到的知識。希望能給對大家…

文件的讀寫及其相關

將軟件布置在第三方電腦上會出現無法提前指定絕對路徑的情況&#xff0c;這回影響到后續的文件讀寫&#xff1b;json文件是數據交換的一種基本方法&#xff0c;為了減少重復造輪子&#xff0c;經行標準化代碼。關于路徑&#xff1a; import os workspaceos.getcwd() pathos.pat…

接口測試框架2

現在市面上做接口測試的工具很多&#xff0c;比如Postman&#xff0c;soapUI, JMeter, Python unittest等等&#xff0c;各種不同的測試工具擁有不同的特色。但市面上的接口測試工具都存在一個問題就是無法完全吻合的去適用沒一個項目&#xff0c;比如數據的處理&#xff0c;加…

python 傳不定量參數_Python中的定量金融

python 傳不定量參數The first quantitative class for vanilla finance and quantitative finance majors alike has to do with the time value of money. Essentially, it’s a semester-long course driving notions like $100 today is worth more than $100 a year from …

axis為amchart左右軸的參數

<axis>left</axis> <!-- [left] (left/ right) indicates which y axis should be used --> <title>流通股</title> <!-- [] (graph title) --> <…

雷軍宣布紅米 Redmi 品牌獨立,這對小米意味著什么?

雷鋒網消息&#xff0c;1 月 3 日&#xff0c;小米公司宣布&#xff0c;將在 1 月 10 日召開全新獨立品牌紅米 Redmi 發布會。從小米公布的海報來看&#xff0c;Redmi 品牌標識出現的倒影中&#xff0c;有 4800 的字樣&#xff0c;這很容易讓人聯想起此前小米總裁林斌所宣布的 …

JAVA的rotate怎么用,java如何利用rotate旋轉圖片_如何在Java中旋轉圖形

I have drawn some Graphics in a JPanel, like circles, rectangles, etc.But I want to draw some Graphics rotated a specific degree amount, like a rotated ellipse. What should I do?解決方案If you are using plain Graphics, cast to Graphics2D first:Graphics2D …

貝葉斯 樸素貝葉斯_手動執行貝葉斯分析

貝葉斯 樸素貝葉斯介紹 (Introduction) Bayesian analysis offers the possibility to get more insights from your data compared to the pure frequentist approach. In this post, I will walk you through a real life example of how a Bayesian analysis can be perform…

vs2005 vc++ 生成非托管的 不需要.net運行環境的exe程序方法

在VS2005里開發的VC程序在編譯的時候&#xff0c;微軟默認會加入自己的 .Net Framework &#xff08;方便推廣自家產品&#xff09;&#xff0c;讓你的VC程序依賴它&#xff0c;這就導致程序編譯后&#xff0c;無法跟往常一樣直接打包&#xff0c;在別的機器就能正常運行。如果…

西工大java實驗報告給,西工大數字集成電路實驗 實驗課6 加法器的設計

西工大數字集成電路實驗練習六 加法器的設計一、使用與非門(NAND)、或非門(NOR)、非門(INV)等布爾邏輯器件實現下面的設計。1、仿照下圖的全加器&#xff0c;實現一個N位的減法器。要求仿照圖1畫出N位減法器的結構。ABABABAB0123圖1 四位逐位進位加法器的結構2、根據自己構造的…

DS二叉樹--二叉樹之數組存儲

二叉樹可以采用數組的方法進行存儲&#xff0c;把數組中的數據依次自上而下,自左至右存儲到二叉樹結點中&#xff0c;一般二叉樹與完全二叉樹對比&#xff0c;比完全二叉樹缺少的結點就在數組中用0來表示。&#xff0c;如下圖所示 從上圖可以看出&#xff0c;右邊的是一顆普通的…

VS IIS Express 支持局域網訪問

使用Visual Studio開發Web網頁的時候有這樣的情況&#xff1a;想要在調試模式下讓局域網的其他設備進行訪問&#xff0c;以便進行測試。雖然可以部署到服務器中&#xff0c;但是卻無法進行調試&#xff0c;就算是注入進程進行調試也是無法達到自己的需求&#xff1b;所以只能在…

前復權后復權程序C# .net

if (win32apitest.MDIMain.SFSDA.FuQuan "前復權") { if (mytime DateTime.Parse("2009-04-29")) { //if (svalue 34.89) …

一天一個js知識

原型繼承和class繼承 class&#xff1a;js中并不存在類的概念&#xff0c;class只是語法糖&#xff0c;本質還是函數&#xff1b; 提升&暫時性死區 console.log(a)// ? a() {} var a8 function a(){} 復制代碼 1、這里說明函數的提升要優先于變量的提升&#xff1b;函數提…