java 类序列化

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java 类序列化相关的知识,希望对你有一定的参考价值。

序列化:
ByteArrayOutputStream obj = new  ByteArrayOutputStream(); 
try
{
    ObjectOutputStream out = new ObjectOutputStream(obj);
    out.writeObject(this);
    return obj.toByteArray();
            
} catch (IOException e) 
{    
    e.printStackTrace();
}
反序列化:
ByteArrayInputStream bin = new ByteArrayInputStream((byte[])objs);
try 
{
    ObjectInputStream obin = new ObjectInputStream(bin);
    Object  obj = obin.readObject();
}
catcch(Exception e)
{
    e.printStackTrace();
}

以上是关于java 类序列化的主要内容,如果未能解决你的问题,请参考以下文章