在Android中,我必须将字节数组转换为字符串,但我的字节数组包含负值。
如果我再次将该字符串转换为字节数组,则得到的值与原始的字节数组值不同。
我可以做些什么来获得正确的转换?我用来进行转换的代码如下:
// Code to convert byte arr to str:
byte[] by_original = {0,1,-2,3,-4,-5,6};
String str1 = new String(by_original);
System.out.println("str1 >> "+str1);
// Code to convert str to byte arr:
byte[] by_new = str1.getBytes();
for(int i=0;i<by_new.length;i++)
System.out.println("by1["+i+"] >> "+str1);
我陷入了这个问题。
https://stackoverflow.com/questions/1536054
复制相似问题