自己写的两个练习
来源:互联网 发布:淘宝运动鞋店铺排行榜 编辑:程序博客网 时间:2024/05/21 11:32
//文件存储ArrayList
public class Data {
public ArrayList<Message> read() {
ArrayList<Message> list=new ArrayList<Message>();
ObjectInputStream ois=null;
File file =new File("e:"+File.separator+"message.txt");
if(file.length()!=0){
try {
ois=new ObjectInputStream(new FileInputStream(file));
if(ois!=null){
list=(ArrayList<Message>) ois.readObject();
}
} catch (IOException | ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return list;
}
public void write(ArrayList<Message> list){
ObjectOutputStream oos=null;
File file =new File("e:"+File.separator+"message.txt");
try {
oos=new ObjectOutputStream(new FileOutputStream(file));
oos.writeObject(list);
oos.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
xml文件写入
public class ObjectAndXmlHandle {
public static void ObjectToXml(Object object){
try {
JAXBContext context=JAXBContext.newInstance(object.getClass());
Marshaller marshaller=context.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);//是否换行
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);//忽略开头
marshaller.setProperty(Marshaller.JAXB_ENCODING, "GBK");//解析格式
OutputStream oStream=new FileOutputStream("e:"+File.separator+"testPerson.xml",true);//输出路径
// marshaller.marshal(object, oStream);
marshaller.marshal(object, System.out);
} catch (Exception e) {
// TODO: handle exception
}
}
}
0 0
- 自己写的两个练习
- 自己写的一个练习程序
- PHP-自己写的代码练习-数组
- 自己写的两个Excel 函数
- XML练习文档 不知道自己写的对不对!
- 分享自己写的一个找CALL练习软件
- 自己写的第一个练习网页【2017.7.12】
- 关于时间戳自己写的两个方法
- 写一函数,实现两个字符串的比较,即自己写一个strcmp函数
- P279_1017 写一函数,实现两个字符串的比较,即自己写一个strcmp函数
- 自己的练习
- 自己练习写的n!末尾零的个数的代码
- 跟着别人做的一些数据库练习,答案都是自己写的,
- 自己写的php无限级分类小练习(地区)
- 自己写的几个练习代码——精简精简再精简
- 看到别人的Python爬虫博客,自己也模仿着写一个,顺便练习一下python
- 自己练习写的Procedure,两种方法遍历cursor,代码已验证
- 项目练习:自己写一个读取指定html文件的Razor
- 数据库的select几种方式的优缺点
- poj 1410 Intersection(矩形和线段交)
- hdu 3466 背包
- Shell编程入门总结(一)
- SNS进阶
- 自己写的两个练习
- AngularJS学习记录-指令复制元素
- 《Hibernate学习笔记四》:Hibernate核心接口介绍
- 哈希表
- poj3685 Matrix(第K大的数)
- Matlab----画彩图
- Java volatile 关键字
- Putty常见错误汇总
- hbase表结构以及操作