java 将字节 [] 转换为 ArrayList<Object>
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11214427/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert byte [] to ArrayList<Object>
提问by evan
I have a byte [] that i obtained using Object ArrayList
我有一个使用 Object ArrayList 获得的字节 []
Can anyone tell me how to convert my byte [] to Object ArrayList?
谁能告诉我如何将我的字节 [] 转换为 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();
垂涎这样的arraylist
ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; oos = new ObjectOutputStream(bos); oos.writeObject(mArrayList);//mArrayList is the array to convert byte[] buff = bos.toByteArray();
Thank you!
谢谢!
回答by Jon Skeet
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();
}
回答by David B
I'm going to go with the obvious answer here...
我将在这里给出明显的答案......
for(byte b : bytearray) {
arraylist.add(new Byte(b));
}