gpt4 book ai didi

java - 将 ArrayList 字符串值转换为字节数组

转载 作者:行者123 更新时间:2023-11-30 02:10:40 25 4
gpt4 key购买 nike

我有一个字符串格式的“Arraylist”,其中包含字节数组的精确值,例如

{-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 84, 0, 0, 0, 84, 8, 6, 0, 0}

我想把它转换回看起来一样的字节数组

{-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0, 0, 0, 84, 0, 0, 0, 84, 8, 6, 0, 0}

但是我找不到方法来做到这一点我想要这个,所以我可以将图像解码出字节数组,但没有运气

我试过用这个方法其中“yolo”是我的数组列表,但输出的 bytearray 具有不同的值,为什么?

ByteArrayOutputStream lp = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(lp);

for (String element : yolo)
{
try
{
out.writeUTF(element);
}catch(IOException e)
{
e.printStackTrace();
}
}

byte myimage[] = lp.toByteArray();

最佳答案

尝试使用循环遍历每个位置并对数组中的每个位置使用 Byte.valueof(yolo[position]),您应该拥有它。

关于java - 将 ArrayList 字符串值转换为字节数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30149916/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com