Javamail中的常见中文乱码问题与解决办法(综合)
中国个人站长站 Javascript 点击数: 更新时间:2007-7-28 3:45:29
String strvalue){
try{ if(strvalue==null) return null; else{ strvalue = new String(strvalue.getBytes("ISO8859_1"), "GBK"); return strvalue; } }catch(Exception e){ return null; } } 3.接收邮件时,获取某个邮件的中文附件名,出现乱码
解决办法:
对于用base64编码过的中文,则采用base64解码,否则对附件名进行ISO8859_1到gbk的编码转换,例如:
- String temp=part.getFileName();//part为Part实例
- if((temp.startsWith("=?GBK?B?")&&temp.endsWith("?="))
- ||(temp.startsWith("=?gbk?b?")&&temp.endsWith("?="))){
- temp=StringUtil.getFromBASE64(temp.substring(8,temp.indexOf("?=")-1));
- }else{
- temp=StringUtil.toChinese(temp);//该方法如前所叙
- }
- /////////////StringUtil的getFromBASE64方法/////////
- public static String getFromBASE64(String s) {
- if (s == null) return null;
- BASE64Decoder decoder =&
上一页 [1] [2] [3] 下一页
教程录入:swh 责任编辑:swh