序列化与反序列化
来源:互联网 发布:女程序员的职业规划 编辑:程序博客网 时间:2024/06/16 05:54
//实体类实现Serializable 接口
public class Worker implements Serializable {
private String passwd;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPasswd() {
return passwd;
}
public void setPasswd(String passwd) {
this.passwd = passwd;
}
}
//序列化将对象写入文件
try
{
File file = new File("E:\\info.txt");
FileOutputStream fos = new FileOutputStream(file);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(worker);
oos.close();
}
catch (IOException e)
{
e.printStackTrace();
}
//反序列化读取文件
try
{
File file = new File("E:\\info.txt");
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois=new ObjectInputStream(fis);
worker=(Worker) ois.readObject();
ois.close();
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
catch (ClassNotFoundException e)
{
e.printStackTrace();
}
- 序列化与反序列
- 序列化与反序列
- XML序列化与反序列化
- 对象序列化与反序列化
- 序列化与反序列化
- 转载:序列化与反序列化
- c#序列化与反序列化
- java序列化与反序列化
- XML序列化与反序列化
- 序列化与反序列化
- 序列化与反序列化
- C#序列化与反序列化
- java序列化与反序列化
- XML序列化与反序列化
- 再看序列化与反序列化
- 序列化与反序列化对象
- 序列化与反序列化
- .NET序列化与反序列化
- hdu4396 spfa有限制的最短路
- 文件的读写
- kermit xmodem ymodem
- 排序算法之六 堆排序
- Memcached原理深度分析详解
- 序列化与反序列化
- 表视图的作用
- 基于Windows的dos命令大全
- web.xml配置总结
- const的进一步理解~
- 多级目录中的Makefile
- FindTask类使用方法
- linux 设置path
- Ajax的get请求