物件序列化好了。不要是內部類。正常的 public Object byteArrayToObject(byte[] buffer)throws Exception{ Object ob = null; ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(buffer)); ob = ois.readObject(); ois.close(); return ob; } public byte[] ObjectToByteArray(DemoObject obj)throws Exception{ byte [] bytes=null; ByteArrayOutputStream baos= new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(obj); oos.close(); bytes=baos.toByteArray(); baos.close(); return bytes; }呼叫示範test.byteArrayToObject( test.ObjectToByteArray(demo) );得到結果,正常的。
物件序列化好了。不要是內部類。正常的 public Object byteArrayToObject(byte[] buffer)throws Exception{ Object ob = null; ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(buffer)); ob = ois.readObject(); ois.close(); return ob; } public byte[] ObjectToByteArray(DemoObject obj)throws Exception{ byte [] bytes=null; ByteArrayOutputStream baos= new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(obj); oos.close(); bytes=baos.toByteArray(); baos.close(); return bytes; }呼叫示範test.byteArrayToObject( test.ObjectToByteArray(demo) );得到結果,正常的。