一:
序列化和反序列化的用法,
objectoutputstream 和objectinputstream
,要在父类后面加上
//public class Person implements Serializable
public class Object {
public static void main(String[] args) {
Person p=new Person("1001",23,"tom");
File file=new File("E:"+File.separator+"note.txt");
ObjectOutputStream oos=null;
ObjectInputStream ois=null;
try {
//构建输出流对象
oos=new ObjectOutputStream
(new FileOutputStream(file));
oos.writeObject(p);
oos.flush();
oos.close();
//构建输入流对象
ois=new ObjectInputStream(new FileInputStream(file));
Person p2=(Person) ois.readObject();
System.out.println(p2.getId()+"\t"+p2.getAge()+"\t"+p2.getName());
} catch (Exception e) {
e.printStackTrace();
}finally{
if(ois!=null){
try {
ois.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();