对象序列化流和反序列化流

对象序列化流和反序列化流,第1张

public static void main(String[] args) throws Exception {

       writeObject();

       readObject();

    }

    /**
     * 反序列化
     */
    private static void readObject() throws IOException, ClassNotFoundException {
        ObjectInputStream ois=new ObjectInputStream(new FileInputStream("11.txt"));
        Object obj = ois.readObject();
        Tetcher s= (Tetcher) obj;
        System.out.println(s.getName()+","+s.getAge());
        ois.close();
    }

    /**
     * 对象序列化
     */
    private static void writeObject() throws IOException {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("11.txt"));
        Tetcher s = new Tetcher("张三", 30);

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/langs/794211.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-06
下一篇2022-05-06

发表评论

登录后才能评论

评论列表(0条)

    保存