java keyword: transient
usage: skip serialization for transient-field
import java.io.*;
class Test implements Serializable
{
int i = 10;
transient int k = 30;
transient static int l = 40;
public static void main(String[] args) throws Exception
{
Test input = new Test();
// write the Test-class obj to the file
FileOutputStream fos = new FileOutputStream("abc.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(input);
// read to Test-class obj from the file
FileInputStream fis = new FileInputStream("abc.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
Test output = (Test)ois.readObject();
}
}
// [OUT]:Test-obj output is { i = 10;k = 0;l = 40}
原文:https://www.cnblogs.com/1river/p/14799763.html