使用BASE64Encoder编码和BASE64Decoder解码中文时,偶数字的显示正常,但奇数就会在最后显示“?”,请高手帮忙
36397 2008-10-03 09:44:35 //BASE64Encoder编码
public static String getBASE64(String s) {
String yyy="";
if (s == null) return null;
BASE64Encoder enc = new BASE64Encoder();
System.out.println("开始编码="+enc.encode(s.getBytes()));
yyy=enc.encode(s.getBytes());
return yyy;
}
//BASE64Encoder解码
public static String getFromBASE64(String s) {
if (s == null)
return null;
BASE64Decoder decoder = new BASE64Decoder();
try {
byte[] b = decoder.decodeBuffer(s);
return new String(b);
} catch (Exception e) {
return null;
}
}
//运行结果
当要编码中文是偶数,如“我母亲中国人”,则解码正常
当要编码中文是奇数,如“母亲中国人”,则解码后,有一个“?”
英文也一样偶数正常,奇数就有“?”了
请高手帮忙