11

I have a byte[] that i obtained using Object ArrayList<Obj>

Can anyone tell me how to convert my byte[] to Object ArrayList?

Coveting ArrayList like this:

ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutputStream oos = null;
oos = new ObjectOutputStream(bos);
 
oos.writeObject(mArrayList);//mArrayList is the array to convert
byte[] buff = bos.toByteArray();

I'm going to go with the obvious answer here...

for(byte b : bytearray) {
  arraylist.add(new Byte(b));
}
4

2 回答 2

18

Now you've given us the information about how you did the conversion one way... you need:

ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
try {
    @SuppressWarnings("unchecked")
    ArrayList<Object> list = (ArrayList<Object>) ois.readObject();
    ...
} finally {
    ois.close();
}
于 2012-06-26T19:36:12.523 回答
-1

我将在这里给出明显的答案......

for(byte b : bytearray) {
  arraylist.add(new Byte(b));
}
于 2012-06-26T19:18:36.040 回答