通过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();

你可能感兴趣的:(序列化)