output:
a=[I@4e25154f:2 5 9 0
Person [name=wang, age=21]
theA=[I@404b9385:2 5 9 0
Person [name=wang, age=21]
public static void main(String[] args) throws IOException, ClassNotFoundException {
int a[]={2,5,9,0};
Person p=new Person("wang", 21);//需要实现 java.io.Serializable接口
ByteArrayOutputStream baos=new ByteArrayOutputStream();
ObjectOutputStream oos=new ObjectOutputStream(baos);
oos.writeObject(a);
oos.writeObject(p);
System.out.print("a="+a+":");
for(int i:a){
System.out.print(i+" ");
}
System.out.println();
System.out.println(p);
ByteArrayInputStream bais=new ByteArrayInputStream(baos.toByteArray());
ObjectInputStream ois=new ObjectInputStream(bais);
int[] theA=(int[]) ois.readObject();
Person theP=(Person) ois.readObject();
System.out.print("theA="+theA+":");
for(int i:theA){
System.out.print(i+" ");
}
System.out.println();
System.out.println(theP);
}