import java.io.Serializable;
public class AnotherClass {
int aInt = 7;
}
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
public class Main implements Serializable {
int bInt = 5;
transient AnotherClass aAnotherClass = new AnotherClass();
public static void main(String[] args) throws Exception {
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("Main.ser"));
Main aMain = new Main();
System.out.println("" + aMain.bInt + aMain.aAnotherClass.aInt);
oos.writeObject(aMain);
oos.close();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("Main.ser"));
aMain = (Main) ois.readObject();
ois.close();
System.out.println("" + aMain.bInt + " " + (aMain.aAnotherClass!=null?aMain.aAnotherClass.aInt:"null"));
}
}
run:
57
5 null
No comments:
Post a Comment