java 对象序列化

Test t = new Test("123456",1);
FileOutputStream fos = new FileOutputStream("D:\\object.txt");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(t);
oos.close();
fos.close();

FileInputStream fis = new FileInputStream("D:\\object.txt");
ObjectInputStream ois = new ObjectInputStream(fis);
Test st = (Test)ois.readObject();
System.out.println(st.s+"  "+st.n);
ois.close();
fis.close();

你可能感兴趣的:(java)