编码的程序是
String tempS = new String(resutlBytesData[p], "UTF-16BE");
byte[] btmp = tempS.getBytes("GBK");
System.out.println(Base64.encode(btmp));
然后我解码的顺序是
byte[] b1 = Base64.decode(s1);
String ss1 = new String(b1,"GBK");
byte[] bb1 = ss1.getBytes("UTF-16BE");
bb1解出来后是resutlBytesData[p],但是不对?哪里出错了吗? 完整的代码如下
public class anotherTest {
public static void main(String[] args) throws UnsupportedEncodingException {
byte[] bytes = {6, 8, 4, 0, 1, 2, 1, 117, 49, 78, -114, 78, 14, 123, 44, 78, 9, 101, -71, 84, 8, 79, 92, -116, 3, 101, 116, -1, 12, 102, -126, 80, 92, -117, -35, -115, 57, 101, 47, 78, -40, 81, 81, 99, 98, 98, 75, 103, 58, 101, 47, 78, -40, 117, 53, 91, 80, 82, 56, -1, 8, 84, 43, 81, 108, 78, -92, 78, 0, 83, 97, -112, 26, 117, 53, 91, 80, 82, 56, -1, 9, 78, 26, 82, -95, 48, 2, -117, -9, 96, -88, -112, 9, 98, -23, 81, 118, 78, -42, 83, -17, -115, 45, 78, 112, 78, -89, 84, -63, 48, 2, -117, -35, -115, 57, 101, 47, 78, -40, 83, -17, -115, 45, 78, 112, 118, -124};
System.out.println("解码前:"+Arrays.toString(bytes));
String tempS = new String(bytes, "UTF-16BE");//得到的tempS就是乱码了
byte[] btmp = tempS.getBytes("GBK");
String result = Base64.encode(btmp);
byte[] rBtemp = Base64.decode(result);
String rTempS = new String(rBtemp,"GBK");
byte[] rBytes = rTempS.getBytes("UTF-16BE");
System.out.println("解码后:"+Arrays.toString(rBytes));
}
}
收到一只叮咚
相关分类