标签:style close ati str har mat NPU test random
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; }
测试Object流(Serializable接口和transient关键字)
标签:style close ati str har mat NPU test random
原文地址:https://www.cnblogs.com/yxfyg/p/12407566.html