![]() |
#2
疯狂的小a2018-06-16 13:13
|

//序列化和反序列化
try
{
File file = new File("F:\\file","name6.txt");
System.out.println(file.getName());
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
Person person=new Person("krusl",12);
out.writeObject(person);
//序列化
out.close();
}
catch(IOException e22)
{
System.out.println("Errorrrrrr");
}
try
{
File file = new File("F:\\file","name6.txt");
//反序列化
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
Object newperson = in.readObject();
in.close();
System.out.println(newperson);
}
catch(IOException e999)
{System.out.println("ssss");}
catch(ClassNotFoundException E111)
{System.out.println("fdfdfd");}
}
try
{
File file = new File("F:\\file","name6.txt");
System.out.println(file.getName());
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
Person person=new Person("krusl",12);
out.writeObject(person);
//序列化
out.close();
}
catch(IOException e22)
{
System.out.println("Errorrrrrr");
}
try
{
File file = new File("F:\\file","name6.txt");
//反序列化
ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
Object newperson = in.readObject();
in.close();
System.out.println(newperson);
}
catch(IOException e999)
{System.out.println("ssss");}
catch(ClassNotFoundException E111)
{System.out.println("fdfdfd");}
}
运行结果:
name6.txt
Person@5ba23b66
理论上应该是krusl,12