package com.lxb.test;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class ObjectOurputStremDemo {
public static void main(String[] args) throws IOException, ClassNotFoundException {
// TODO Auto-generated method stub
writeObject();
readObject();
}
private static void readObject() throws IOException, IOException, ClassNotFoundException {
// TODO Auto-generated method stub
ObjectInputStream ois=new ObjectInputStream(new FileInputStream("e:\\demo.object"));
//对象序列化,被序列化的对象必须实现serilizable接口
Object obj=ois.readObject();
ois.close();
Person p=(Person) obj;
System.out.println(p.getName()+":"+p.getAge());
}
private static void writeObject() throws IOException, IOException {
// TODO Auto-generated method stub
ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("e:\\demo.object"));
//对象序列化,被序列化的对象必须实现serilizable接口
oos.writeObject(new Person("王五",30));
oos.close();
}
}
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
public class ObjectOurputStremDemo {
public static void main(String[] args) throws IOException, ClassNotFoundException {
// TODO Auto-generated method stub
writeObject();
readObject();
}
private static void readObject() throws IOException, IOException, ClassNotFoundException {
// TODO Auto-generated method stub
ObjectInputStream ois=new ObjectInputStream(new FileInputStream("e:\\demo.object"));
//对象序列化,被序列化的对象必须实现serilizable接口
Object obj=ois.readObject();
ois.close();
Person p=(Person) obj;
System.out.println(p.getName()+":"+p.getAge());
}
private static void writeObject() throws IOException, IOException {
// TODO Auto-generated method stub
ObjectOutputStream oos=new ObjectOutputStream(new FileOutputStream("e:\\demo.object"));
//对象序列化,被序列化的对象必须实现serilizable接口
oos.writeObject(new Person("王五",30));
oos.close();
}
}