通過ObjectOutputStream序列化和使用ObjectInputStream反序列化


        ObjectOutputStream oos = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream("test.dat")));
        oos.writeObject("hello++++12345");
        oos.writeObject("is verygood");
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(new FileInputStream("test.dat")));
        String s1 = (String) ois.readObject();
        String s2 = (String) ois.readObject();
        System.out.println(s1);
        System.out.println(s2);
        ois.close();

發佈了63 篇原創文章 · 獲贊 2 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章