IO(2)

properties 配置文件

对象流
ObjectOutputStream / ObjectInputSteam Serializable 对象实体类 实现此接口 并固定一个序列号
private static final long serialVersionUID = 1L;
//固定一个序列号序列化
public class TestObjectOutputStrream {
public static void main(String[] args) throws FileNotFoundException, IOException {
TestPerson tp=new TestPerson(“张三”, 14);
ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream(“F:/一阶段笔记/对象流.txt”)); oos.writeObject(tp);
oos.close();
}}
反序列化
public class TestObjectInputStream {
//反序列化 public static void main(String[] args) throws Exception, IOException {
ObjectInputStream ois=new ObjectInputStream(new FileInputStream(“F:/一阶段笔记/对象流.txt”));
String obj=(String) ois.readObject();
// 返回读反序列化的数据
ois.close();
System.out.println(obj);
}
}

猜你喜欢

转载自blog.csdn.net/qq_42435514/article/details/82901963