*:first-child {
margin-top: 0 !important; }
body > *:last-child {
margin-bottom: 0 !important; }
a {
color: #4183C4;
text-decoration: none; }
a.absent {
color: #cc0000; }
a.anchor {
display: block;
padding-left: 30px;
margin-left: -30px;
cursor: pointer;
position: absolute;
top: 0;
left: 0;
bottom: 0; }
h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
cursor: text;
position: relative; }
h1:hover a.anchor, h2:hover a.anchor, h3:hover a.anchor, h4:hover a.anchor, h5:hover a.anchor, h6:hover a.anchor {
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA09pVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMy1jMDExIDY2LjE0NTY2MSwgMjAxMi8wMi8wNi0xNDo1NjoyNyAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNiAoMTMuMCAyMDEyMDMwNS5tLjQxNSAyMDEyLzAzLzA1OjIxOjAwOjAwKSAgKE1hY2ludG9zaCkiIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6OUM2NjlDQjI4ODBGMTFFMTg1ODlEODNERDJBRjUwQTQiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6OUM2NjlDQjM4ODBGMTFFMTg1ODlEODNERDJBRjUwQTQiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo5QzY2OUNCMDg4MEYxMUUxODU4OUQ4M0REMkFGNTBBNCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo5QzY2OUNCMTg4MEYxMUUxODU4OUQ4M0REMkFGNTBBNCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PsQhXeAAAABfSURBVHjaYvz//z8DJYCRUgMYQAbAMBQIAvEqkBQWXI6sHqwHiwG70TTBxGaiWwjCTGgOUgJiF1J8wMRAIUA34B4Q76HUBelAfJYSA0CuMIEaRP8wGIkGMA54bgQIMACAmkXJi0hKJQAAAABJRU5ErkJggg==) no-repeat 10px center;
text-decoration: none; }
h1 tt, h1 code {
font-size: inherit; }
h2 tt, h2 code {
font-size: inherit; }
h3 tt, h3 code {
font-size: inherit; }
h4 tt, h4 code {
font-size: inherit; }
h5 tt, h5 code {
font-size: inherit; }
h6 tt, h6 code {
font-size: inherit; }
h1 {
font-size: 28px;
color: black; }
h2 {
font-size: 24px;
border-bottom: 1px solid #cccccc;
color:#00ccff;
margin: 25px auto 12px auto;
padding-bottom: 2px;
}
h3 {
font-size: 18px;
color:#993300;}
h4 {
font-size: 16px; }
h5 {
font-size: 14px; }
h6 {
color: #777777;
font-size: 14px; }
p, blockquote, ul, ol, dl, li, table, pre {
margin: 0 0; }
/*hr {
background: transparent url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAYAAAAECAYAAACtBE5DAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyJpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuMC1jMDYwIDYxLjEzNDc3NywgMjAxMC8wMi8xMi0xNzozMjowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvIiB4bWxuczp4bXBNTT0iaHR0cDovL25zLmFkb2JlLmNvbS94YXAvMS4wL21tLyIgeG1sbnM6c3RSZWY9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9zVHlwZS9SZXNvdXJjZVJlZiMiIHhtcDpDcmVhdG9yVG9vbD0iQWRvYmUgUGhvdG9zaG9wIENTNSBNYWNpbnRvc2giIHhtcE1NOkluc3RhbmNlSUQ9InhtcC5paWQ6OENDRjNBN0E2NTZBMTFFMEI3QjRBODM4NzJDMjlGNDgiIHhtcE1NOkRvY3VtZW50SUQ9InhtcC5kaWQ6OENDRjNBN0I2NTZBMTFFMEI3QjRBODM4NzJDMjlGNDgiPiA8eG1wTU06RGVyaXZlZEZyb20gc3RSZWY6aW5zdGFuY2VJRD0ieG1wLmlpZDo4Q0NGM0E3ODY1NkExMUUwQjdCNEE4Mzg3MkMyOUY0OCIgc3RSZWY6ZG9jdW1lbnRJRD0ieG1wLmRpZDo4Q0NGM0E3OTY1NkExMUUwQjdCNEE4Mzg3MkMyOUY0OCIvPiA8L3JkZjpEZXNjcmlwdGlvbj4gPC9yZGY6UkRGPiA8L3g6eG1wbWV0YT4gPD94cGFja2V0IGVuZD0iciI/PqqezsUAAAAfSURBVHjaYmRABcYwBiM2QSA4y4hNEKYDQxAEAAIMAHNGAzhkPOlYAAAAAElFTkSuQmCC) repeat-x 0 0;
border: 0 none;
color: #cccccc;
height: 4px;
padding: 0;
}*/
hr {
margin: 0 0 19px;
border: 0;
border-bottom: 1px solid #ccc;
}
body > h2:first-child {
margin-top: 0;
padding-top: 0; }
body > h1:first-child {
margin-top: 0;
padding-top: 0; }
body > h1:first-child + h2 {
margin-top: 0;
padding-top: 0; }
body > h3:first-child, body > h4:first-child, body > h5:first-child, body > h6:first-child {
margin-top: 0;
padding-top: 0; }
a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
margin-top: 0;
padding-top: 0; }
h1 p, h2 p, h3 p, h4 p, h5 p, h6 p {
margin-top: 0; }
li p.first {
display: inline-block; }
li {
margin: 0; }
ul, ol {
padding-left: 30px; }
ul :first-child, ol :first-child {
margin-top: 0; }
dl {
padding: 0; }
dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px; }
dl dt:first-child {
padding: 0; }
dl dt > :first-child {
margin-top: 0; }
dl dt > :last-child {
margin-bottom: 0; }
dl dd {
margin: 0 0 15px;
padding: 0 15px; }
dl dd > :first-child {
margin-top: 0; }
dl dd > :last-child {
margin-bottom: 0; }
blockquote {
border-left: 4px solid #dddddd;
padding: 0 15px;
color: #777777; }
blockquote > :first-child {
margin-top: 0; }
blockquote > :last-child {
margin-bottom: 0; }
/*table {
padding: 0;border-collapse: collapse; }
table tr {
border-top: 1px solid #cccccc;
background-color: white;
margin: 0;
padding: 0; }
table tr:nth-child(2n) {
background-color: #f8f8f8; }
table tr th {
font-weight: bold;
border: 1px solid #cccccc;
margin: 0;
padding: 6px 13px; }
table tr td {
border: 1px solid #cccccc;
margin: 0;
padding: 6px 13px; }
table tr th :first-child, table tr td :first-child {
margin-top: 0; }
table tr th :last-child, table tr td :last-child {
margin-bottom: 0; }*/
img {
max-width: 100%; }
span.frame {
display: block;
overflow: hidden; }
span.frame > span {
border: 1px solid #dddddd;
display: block;
float: left;
overflow: hidden;
margin: 13px 0 0;
padding: 7px;
width: auto; }
span.frame span img {
display: block;
float: left; }
span.frame span span {
clear: both;
color: #333333;
display: block;
padding: 5px 0 0; }
span.align-center {
display: block;
overflow: hidden;
clear: both; }
span.align-center > span {
display: block;
overflow: hidden;
margin: 13px auto 0;
text-align: center; }
span.align-center span img {
margin: 0 auto;
text-align: center; }
span.align-right {
display: block;
overflow: hidden;
clear: both; }
span.align-right > span {
display: block;
overflow: hidden;
margin: 13px 0 0;
text-align: right; }
span.align-right span img {
margin: 0;
text-align: right; }
span.float-left {
display: block;
margin-right: 13px;
overflow: hidden;
float: left; }
span.float-left span {
margin: 13px 0 0; }
span.float-right {
display: block;
margin-left: 13px;
overflow: hidden;
float: right; }
span.float-right > span {
display: block;
overflow: hidden;
margin: 13px auto 0;
text-align: right; }
code, tt {
margin: 0 2px;
padding: 0 0px;
white-space: nowrap;
/*background-color: #fff;*/
color: rgba(51, 102, 255, 255);
/*border: 1px solid #eaeaea;*/
/*background-color: #f8f8f8;*/
/*border-radius: 3px; */}
pre code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
color: rgba(0, 0, 0, 255);
background: transparent; }
.highlight pre {
background-color: #f8f8f8;
border: 1px solid #cccccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px; }
pre {
background-color: #f8f8f8;
border: 1px solid #cccccc;
font-size: 14px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px; }
pre code, pre tt {
background-color: transparent;
border: none; }
sup {
font-size: 0.83em;
vertical-align: super;
line-height: 0;
}
* {
-webkit-print-color-adjust: exact;
}
@media screen and (min-width: 914px) {
body {
/*width: 854px;*/
/*margin:0 auto;*/
}
}
@media print {
table, pre {
page-break-inside: avoid;
}
pre {
word-wrap: break-word;
}
}
#cnblogs_post_body li ul li {
list-style-type: circle !important;
}
#cnblogs_post_body a {
text-decoration: none;
color: #4183C4;
}
#mainContent .postBody h2 {
margin: 25px auto 12px auto;
padding-bottom: 2px;
}
-->
存储数据(上)
这篇文章学到的内容:
1、key-value形式数据的存储方式
2、xml的存储方式
app都要存储数据。androd提供到了四种存储数据的方式:
1、使用shared preferences文件来存储key-value。
2、使用xml存储
3、使用数据库存储。
4、使用文件存储。
这里介绍前两种。
如果你的数据非常的少,比如,就几个key-value值需要存储。如存储玩家玩游戏的进度,存储积分,这些数据都可以用一个key来查询出对应的value,那采用第一种。
如果你的数据有非常多的key-value,建议用xml来存储,而且xml还可以存储较为复杂的数据。
如果你的数据要经常使用快速的增删改查,那就要采用数据库来存储了。
接下来详细的介绍这两种存储方式吧。
key-value形式数据的存储方式
SharedPreferences提供了一个文件来记录key和value值。它也提供了简单的方法来对这些key和value进行读和写。
SharedPreferences提供了两种方法来得到SharedPreferences文件:
1、getSharePrefences()如果你的应用会用到多个SharedPreferences文件,用这个方法。
2、getPreferences()得到这个Activity对应的SharedPreferences文件。
代码如下:
1 package com.babybus.study.savingdata.sharepreferneces; 2 3 import android.app.Activity; 4 import android.content.Context; 5 import android.content.SharedPreferences; 6 7 /** 8 * SharePreferences工具类 9 * @author k-yuyonghao 10 * 11 */ 12 public class BBSharePreferencesUtil { 13 14 public static void saveData(Context cxt, String sharePreferencesFileName, String key, String value) { 15 16 SharedPreferences sharedPref = cxt.getSharedPreferences(sharePreferencesFileName, Context.MODE_PRIVATE); 17 SharedPreferences.Editor editor = sharedPref.edit(); 18 editor.putString(key, value); 19 editor.commit(); 20 } 21 22 public static void saveData(Context cxt, String sharePreferencesFileName, String key, int value) { 23 24 SharedPreferences sharedPref = cxt.getSharedPreferences(sharePreferencesFileName, Context.MODE_PRIVATE); 25 SharedPreferences.Editor editor = sharedPref.edit(); 26 editor.putInt(key, value); 27 editor.commit(); 28 } 29 30 public static void saveData(Context cxt, String sharePreferencesFileName, String key, boolean value) { 31 32 SharedPreferences sharedPref = cxt.getSharedPreferences(sharePreferencesFileName, Context.MODE_PRIVATE); 33 SharedPreferences.Editor editor = sharedPref.edit(); 34 editor.putBoolean(key, value); 35 editor.commit(); 36 } 37 38 public static String readStringData(Context cxt, String sharePreferencesFileName, String key) { 39 40 SharedPreferences sharedPref = cxt.getSharedPreferences(sharePreferencesFileName, Context.MODE_PRIVATE); 41 return sharedPref.getString(key, null); 42 } 43 44 public static Integer readIntegerData(Context cxt, String sharePreferencesFileName, String key) { 45 46 SharedPreferences sharedPref = cxt.getSharedPreferences(sharePreferencesFileName, Context.MODE_PRIVATE); 47 return sharedPref.getInt(key, -1); 48 } 49 50 public static Boolean readBooleanData(Context cxt, String sharePreferencesFileName, String key) { 51 52 SharedPreferences sharedPref = cxt.getSharedPreferences(sharePreferencesFileName, Context.MODE_PRIVATE); 53 return sharedPref.getBoolean(key, false); 54 } 55 56 57 public static void saveData(Activity act, String key, String value) { 58 59 SharedPreferences sharedPref = act.getPreferences(Context.MODE_PRIVATE); 60 SharedPreferences.Editor editor = sharedPref.edit(); 61 editor.putString(key, value); 62 editor.commit(); 63 } 64 65 public static void saveData(Activity act, String key, int value) { 66 67 SharedPreferences sharedPref = act.getPreferences(Context.MODE_PRIVATE); 68 SharedPreferences.Editor editor = sharedPref.edit(); 69 editor.putInt(key, value); 70 editor.commit(); 71 } 72 73 public static void saveData(Activity act, String key, boolean value) { 74 75 SharedPreferences sharedPref = act.getPreferences(Context.MODE_PRIVATE); 76 SharedPreferences.Editor editor = sharedPref.edit(); 77 editor.putBoolean(key, value); 78 editor.commit(); 79 } 80 81 public static String readStringData(Activity act, String key) { 82 83 SharedPreferences sharedPref = act.getPreferences(Context.MODE_PRIVATE); 84 return sharedPref.getString(key, null); 85 } 86 87 public static Integer readIntegerData(Activity act, String key) { 88 89 SharedPreferences sharedPref = act.getPreferences(Context.MODE_PRIVATE); 90 return sharedPref.getInt(key, -1); 91 } 92 93 public static Boolean readBooleanData(Activity act, String key) { 94 95 SharedPreferences sharedPref = act.getPreferences(Context.MODE_PRIVATE); 96 return sharedPref.getBoolean(key, false); 97 } 98 }
xml的存储方式
android建议使用pull方式来对xml进行读写。
有的时候,我们需要类似xml那样的结构来存储数据。例如,我需要存储一个班级中的每个学生的信息。学生有姓名,性别,年龄,籍贯等,这些复杂的数据,用sharePreferences来存储显然是不合适的。当然,你可也说,那我可以用数据库,但如果只有几百个学生,没必要用数据库啦,最好的方式,就是把这些信息存放在xml文件里去管理,有轻量又方便。
例如这样的数据:
1 <class> 2 <student> 3 <id>1</id> 4 <name>奇奇</name> 5 <sex>男</sex> 6 <age>3</age> 7 <address>宝宝巴士熊猫镇竹林村123弄</address> 8 </student> 9 <student> 10 <id>2</id> 11 <name>妙妙</name> 12 <sex>女</sex> 13 <age>2</age> 14 <address>宝宝巴士熊猫镇竹林村123弄</address> 15 </student> 16 <student> 17 <id>3</id> 18 <name>兔一一</name> 19 <sex>女</sex> 20 <age>2</age> 21 <address>宝宝巴士兔坡512洞3号</address> 22 </student> 23 <student> 24 <id>4</id> 25 <name>小皮猴</name> 26 <sex>男</sex> 27 <age>5</age> 28 <address>宝宝巴士花果山180街66号</address> 29 </student> 30 </class>
我们一起尝试着写一段代码,在手机的sdcard卡里创建一个xml文件,写入这些学生的信息,然后再把他们读取出来。(掌握了这样的操作,xml的读写就差不多了。)
1、先根据xml格式创建两个类:ClassPo类和StudentPo类。
StudentPo
1 public class StudentPo { 2 3 private int id; 4 private String name; 5 private byte sex; 6 private int age; 7 private String address; 8 9 10 11 public int getId() { 12 return id; 13 } 14 public void setId(int id) { 15 this.id = id; 16 } 17 public String getName() { 18 return name; 19 } 20 public void setName(String name) { 21 this.name = name; 22 } 23 public byte getSex() { 24 return sex; 25 } 26 public void setSex(byte sex) { 27 this.sex = sex; 28 } 29 public int getAge() { 30 return age; 31 } 32 public void setAge(int age) { 33 this.age = age; 34 } 35 public String getAddress() { 36 return address; 37 } 38 public void setAddress(String address) { 39 this.address = address; 40 } 41 }
我们根据xml定义了一个po。
ClassPo类
1 public class ClassPo { 2 3 4 private List<StudentPo> students; 5 6 /** 7 * 获得学生的信息 8 * @return 9 */ 10 public List<StudentPo> getStudents() { 11 return students; 12 } 13 /** 14 * 把学生信息写入xml中 15 * @param infos 16 */ 17 public void setInfos(List<StudentPo> students) { 18 this.students = students; 19 } 20 }
最重要的,就是使用android提供的XmlSerializer,来进行文件的写和读操作。我在此写了一个管理xml读和写的类:
PullBBStudentService:
1 package com.babybus.study.savingdata.xml; 2 3 import java.io.InputStream; 4 import java.io.OutputStream; 5 import java.util.ArrayList; 6 import java.util.List; 7 8 import org.xmlpull.v1.XmlPullParser; 9 import org.xmlpull.v1.XmlSerializer; 10 11 import android.util.Xml; 12 13 /** 14 * 使用pull方法来存储学生信息 15 * @author k-yuyonghao 16 * 17 */ 18 public class PullBBStudentService { 19 20 21 /** 22 * 保存classPo 23 * @param classPo 24 * @param outStream 25 * @param rn 根节点 26 */ 27 public static void saveClassInfo(ClassPo classPo, OutputStream outStream) throws Exception{ 28 29 XmlSerializer serializer = Xml.newSerializer(); 30 serializer.setOutput(outStream, "UTF-8"); 31 serializer.startDocument("UTF-8", true); 32 serializer.startTag(null, "class"); 33 if (classPo != null) { 34 ArrayList<StudentPo> students = (ArrayList<StudentPo>) classPo.getStudents(); 35 if (students != null && students.size() > 0) { 36 for (StudentPo student : students) { 37 38 // 得到信息 39 int id = student.getId(); 40 String name = student.getName(); 41 byte sex = student.getSex(); 42 String address = student.getAddress(); 43 int age = student.getAge(); 44 45 // 把信息写入 46 serializer.startTag(null, "student"); 47 serializer.startTag(null, "id"); 48 serializer.text(id + ""); 49 serializer.endTag(null, "id"); 50 51 serializer.startTag(null, "name"); 52 serializer.text(name + ""); 53 serializer.endTag(null, "name"); 54 55 serializer.startTag(null, "sex"); 56 serializer.text(sex + ""); 57 serializer.endTag(null, "sex"); 58 59 serializer.startTag(null, "age"); 60 serializer.text(age + ""); 61 serializer.endTag(null, "age"); 62 63 serializer.startTag(null, "address"); 64 serializer.text(address + ""); 65 serializer.endTag(null, "address"); 66 serializer.endTag(null, "student"); 67 } 68 } 69 serializer.endTag(null, "class"); 70 serializer.endDocument(); 71 outStream.flush(); 72 outStream.close(); 73 } 74 } 75 76 /** 77 * 把xml文件中的数据读取出来 78 * @param inStream 79 * @return 80 * @throws Exception 81 * <uti-8> 82 */ 83 public static ClassPo getClassInfo(InputStream inStream) throws Exception{ 84 85 ClassPo classPo = null; 86 List<StudentPo> students = null; 87 StudentPo student = null; 88 89 XmlPullParser pullParser = Xml.newPullParser(); 90 pullParser.setInput(inStream, "UTF-8"); 91 int event = pullParser.getEventType(); 92 while (event != XmlPullParser.END_DOCUMENT) { 93 94 String eventName = pullParser.getName(); 95 switch (event) { 96 case XmlPullParser.START_DOCUMENT: 97 // 开始初始化 98 classPo = new ClassPo(); 99 students= new ArrayList<StudentPo>(); 100 break; 101 case XmlPullParser.START_TAG: 102 String key = eventName; 103 104 if (key != null && "student".equals(key)) { 105 106 student = new StudentPo(); 107 108 } 109 if (key != null && "id".equals(key)) { 110 111 int id = student.getId(); 112 if (student != null) { 113 student.setId(id); 114 } 115 } 116 if (key != null && "name".equals(key)) { 117 118 String name = student.getName(); 119 if (student != null) { 120 student.setName(name); 121 } 122 } 123 if (key != null && "sex".equals(key)) { 124 125 byte sex = student.getSex(); 126 if (student != null) { 127 student.setSex(sex); 128 } 129 } 130 if (key != null && "age".equals(key)) { 131 132 int age = student.getAge(); 133 if (student != null) { 134 student.setAge(age); 135 } 136 } 137 if (key != null && "address".equals(key)) { 138 139 String address = student.getAddress(); 140 if (student != null) { 141 student.setAddress(address); 142 } 143 } 144 145 break; 146 case XmlPullParser.END_TAG: 147 if (students != null) { 148 if (student != null) { 149 students.add(student); 150 } 151 152 } 153 student = null; 154 break; 155 } 156 event = pullParser.next(); 157 } 158 // 把信息写入到classPo类中 159 classPo.setInfos(students); 160 return classPo; 161 } 162 }
使用这两个方法,就可以把学生的信息存储在xml中,也可以从xml文件中,读取每一个学生信息到内存中。
(Note:在这里提一个,pull方式写xml是非常快的,如果你要修改某个学生信息,该怎么做呢?在这里告诉我的工作经验,就是把这些信息全部读出来,然后修改List中对应的学生信息后,你可也使用hasnmap来存储,这样查询速度就非常快。再全部重新写入进去。pull方式写xml是非常快的,在此你不用担心效率问题,这样就解决了修改的问题。)
本站文章为宝宝巴士 SD.Team原创,转载务必在明显处注明:(作者官方网站:宝宝巴士)
转载自【宝宝巴士SuperDo团队】 原文链接: http://www.cnblogs.com/superdo/p/4716495.html