package serialization;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
public class WriteObject {
public static void main(String[] args) {
System.out.println("我们正在写入Objcet.....");
Person wang = new Person(111,"Wangweida");
Person yan = new Person(222,"Yanting");
System.out.println(wang);
System.out.println(yan);
try(FileOutputStream fs = new FileOutputStream("person.bin")){
ObjectOutputStream os = new ObjectOutputStream(fs);
os.writeObject(wang);
os.writeObject(yan);
os.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}