加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 将byte []转换为ArrayList

发布时间:2020-12-15 00:21:16 所属栏目:Java 来源:网络整理
导读:我有一个字节[],我使用Object ArrayList获得 有人可以告诉我如何将我的byte []转换成Object ArrayList? coveting arraylist这样 ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; oos = new ObjectOutputStream(b
我有一个字节[],我使用Object ArrayList获得

有人可以告诉我如何将我的byte []转换成Object ArrayList?

coveting 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();

谢谢!

解决方法

现在,您已经向我们提供了有关您如何以某种方式进行转换的信息…您需要:
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes));
try {
    @SuppressWarnings("unchecked")
    ArrayList<Object> list = (ArrayList<Object>) ois.readObject();
    ...
} finally {
    ois.close();
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读