`
weina
  • 浏览: 142337 次
  • 性别: Icon_minigender_2
  • 来自: 北京
社区版块
存档分类
最新评论

java 序列化对象 反序列化对象

    博客分类:
  • java
阅读更多

    /** Read the object from Base64 string. */
    private static Object fromString(String s) throws IOException, ClassNotFoundException {
        byte[] data = new BASE64Decoder().decodeBuffer(s);
        ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(data));
        Object o = ois.readObject();
        ois.close();
        return o;
    }

    /** Write the object to a Base64 string. */
    private static String toString(Object o) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(o);
        oos.close();
        return new String(new BASE64Encoder().encode(baos.toByteArray()));

    }

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics