package test;
import java.io.*;
public class Test implements Serializable{
int i=0;
//不让变量j序列化
transient int j=0;
public static void main(String[] args) {
Test test=new Test();
test.i=3;
test.j=7;
System.out.println(test.i);
System.out.println(test.j);
//存
FileOutputStream fileStream = null;
try {
fileStream = new FileOutputStream("c:\\test.obj");
ObjectOutputStream out = new ObjectOutputStream(fileStream);
out.writeObject(test);
out.close();
}
catch (Exception ex) {
}
try {
//取
FileInputStream fileStream1 = new FileInputStream("c:\\product.obj");
ObjectInputStream in = new ObjectInputStream(fileStream1);
Test test1 = (Test)in.readObject();
System.out.println(test1.i);
//j没有被序列化
System.out.println(test1.j);
in.close();
}
catch (Exception ex) {
}
}
}
本文地址:http://com.8s8s.com/it/it17378.htm