IO流16 --- 对象流操作字符串 --- 技术搬运工(尚硅谷)

序列化

@Test
public void test12() throws IOException {
    ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("object.dat"));
    oos.writeObject(new String("白发渔樵江渚上"));
    oos.close();
}

反序列化

@Test
public void test13() throws IOException, ClassNotFoundException {
    ObjectInputStream ois = new ObjectInputStream(new FileInputStream("object.dat"));
    Object o = ois.readObject();
    System.out.println(o);
    ois.close();
}
原文地址:https://www.cnblogs.com/noyouth/p/11751190.html