测试Object流(Serializable接口和transient关键字)
import java.io.*; import java.util.*; public class ObjectSerializable{ public static void main(String[] args){ try{ ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:/Java/ObjectSerializable/test.txt")); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("D:/Java/ObjectSerializable/test.txt")); oos.writeObject(new T()); oos.flush(); oos.close(); T t = (T)ois.readObject(); System.out.println("a=" + t.a + " b=" + t.b + " c=" + t.c + " d=" + t.d); ois.close(); } catch(IOException e){ e.printStackTrace(); } catch(ClassNotFoundException e){ e.printStackTrace(); } } } class T implements Serializable{ int a = 2; double b = Math.random(); char c = ‘a‘; transient int d = 10; }
相关推荐
huimeiad 2020-11-23
luguanyou 2020-10-05
Mynamezhuang 2020-09-18
充满诗意的联盟 2020-08-23
yfightfors 2020-08-16
jeason 2020-07-20
gaitiangai 2020-07-19
JessePinkmen 2020-07-19
phpboy 2020-07-19
嵌入式移动开发 2020-07-05
HappinessCat 2020-07-05
zhanglao 2020-06-26
Henryztong 2020-06-25
Testingba工作室 2020-06-22
starzhangkiss 2020-06-22
maxelliot 2020-06-21
xiaouncle 2020-06-20
chichichi0 2020-06-16