81,094
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) throws Exception {
byte[] bys1 = {98, 95, -127, 15, 32, 3, 0, 9};
System.out.println(Arrays.toString(bys1));
BASE64Encoder encoder = new BASE64Encoder();
String str = encoder.encode(bys1);
BASE64Decoder decoder = new BASE64Decoder();
byte[] bys2 = decoder.decodeBuffer(str);
System.out.println(Arrays.toString(bys2));
}
具体到你这个需求
HttpURLConnection conn = (HttpURLConnection) realUrl.openConnection();
out = conn.getOutputStream();
byte[] a = new byte[]{98,95,-127,15,52,3,0,9};
BASE64Encoder encoder = new BASE64Encoder();
String str = "a=" + encoder.encode(a);
byte[] b = str.getBytes();
out.write(b);
String str = request.getParameter("a");
BASE64Decoder decoder = new BASE64Decoder();
byte[] a = decoder.decodeBuffer(str);
public static void main(String[] args) {
byte[] bys = {98, 95, -127, 15, 32, 3, 0, 9};
System.out.println(Arrays.toString(bys));
String str = new String(bys);
System.out.println(Arrays.toString(str.getBytes()));
}
修复上面这个程序的问题很简单,使用iso-8859-1编码骗一下编码器
public static void main(String[] args) throws Exception {
byte[] bys = {98, 95, -127, 15, 32, 3, 0, 9};
System.out.println(Arrays.toString(bys));
String str = new String(bys, "iso-8859-1");
System.out.println(Arrays.toString(str.getBytes("iso-8859-1")));
}