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();
}

 

posted @ 2019-10-28 11:24  地中有山  阅读(128)  评论(0编辑  收藏  举报