是的,这称为序列化!
String serializedObject = ""; // serialize the object try { ByteArrayOutputStream bo = new ByteArrayOutputStream(); ObjectOutputStream so = new ObjectOutputStream(bo); so.writeObject(myObject); so.flush(); serializedObject = bo.toString(); } catch (Exception e) { System.out.println(e); } // deserialize the object try { byte b[] = serializedObject.getBytes(); ByteArrayInputStream bi = new ByteArrayInputStream(b); ObjectInputStream si = new ObjectInputStream(bi); MyObject obj = (MyObject) si.readObject(); } catch (Exception e) { System.out.println(e); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)