0 0

Android 深层拷贝对象如何实现?25

try {    
        // Write the object out to a byte array    
        ByteArrayOutputStream bos = new ByteArrayOutputStream();    
        ObjectOutputStream out = new ObjectOutputStream(bos);    
        out.writeObject(list);    
        out.flush();    
        out.close();    
   
        // Retrieve an input stream from the byte array and read    
        // a copy of the object back in.    
        ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());     
        ObjectInputStream in = new ObjectInputStream(bis);    
        copyContactItemLists = (List)in.readObject();    
    } catch (IOException e) {    
        e.printStackTrace();    
    } catch (ClassNotFoundException cnfe) {    
        cnfe.printStackTrace();    
    }    

上面的代码如果在android实现的话就会出现IOException异常?刚开始我怀疑是权限问题,加上<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />还是不行?
请问在android上如何实现深层拷贝?
2011年8月16日 14:20

2个答案 按时间排序 按投票排序

0 0

在网络中传输对象必须可序列化。

2011年8月23日 11:39
0 0

你把异常的信息贴出来看看呢?

2011年8月22日 10:17

相关推荐

Global site tag (gtag.js) - Google Analytics