序列化:
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();
}
时间: 2024-11-08 09:19:04