private static final long serialVersionUID = xxxxL;
import java.io.Serializable;
public class Person implements Serializable
{
private static final long serialVersionUID = 1234567890L;
public int id;
public String name;
public Person(int id, String name)
{
this.id = id;
this.name = name;
}
public String toString()
{
return "Person: " + id + " " + name;
}
}
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
public class SerialTest
{
public static void main(String[] args) throws IOException
{
Person person = new Person(1234, "wang");
System.out.println("Person Serial" + person);
FileOutputStream fos = new FileOutputStream("Person.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(person);
oos.flush();
oos.close();
}
}
import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
public class DeserialTest
{
public static void main(String[] args) throws IOException, ClassNotFoundException
{
Person person;
FileInputStream fis = new FileInputStream("Person.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
person = (Person) ois.readObject();
ois.close();
System.out.println("Person Deserial" + person);
}
}
import java.io.Serializable;
public class Person implements Serializable
{
private static final long serialVersionUID = 123456789L;
public int id;
public String name;
public int age;
public Person(int id, String name)
{
this.id = id;
this.name = name;
}
public String toString()
{
return "Person: " + id + " " + name;
}
}
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
public class SerialTest
{
public static void main(String[] args) throws IOException
{
Person person = new Person(1234, "wang");
System.out.println("Person Serial" + person + " age:" + person.age);
FileOutputStream fos = new FileOutputStream("Person.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(person);
oos.flush();
oos.close();
}
}
Person Deserial Person: 1234 wang age: 0
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有