最简单的解决方案,用类似下面的方法转换一下,注意异常问题
public static String convertStr(String str){ try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859-1");
String temp=new String(temp_t);
return temp;
}
catch(Exception e)
{
}
}
public static String convertStr(String str){ try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859-1");
String temp=new String(temp_t);
return temp;
}
catch(Exception e)
{
}
}
解决方案 »
- 关于Java Socket从输入流中read时阻塞
- 实例和对象的联系是什么
- 在本地机子上可以运行java3D的APPLET,但是放到服务器上后,在客户端浏览器就不能运行,WHY?(解决高分赠送)
- 如果一个异常发生,但一个合适的异常处理都没有找到,那么会发生什么?
- sos sos !!!!1求救 在线等待!!!急急 !!
- 如何控制一个java程序只有一个运行实例(高分求助,在线等待!)
- 我怎么不能发帖子?
- 高手请帮忙!!JAVAMAIL开发接收中文附件问题,解决再送100
- C++ TO JAVA请大家推荐几本好书!
- 关于子类继承父类函数调用问题
- 有谁能详细讲一下hashcode的主要用途和具体用法啊?
- 请教一个switch分支选择的问题(最后70分相送了)
有的是用big5,这样的话就比较麻烦了,需要判断不同的字符集编码方式,再用相应的转换.
String lowercasestr=headstr.toLowerCase();
if(lowercasestr.indexOf("charset=gb2312")>=0||lowercasestr.indexOf("charset=gbk")>=0){
return true;
}
else{
return false;
}
}
==========================================
isChineseCharSet(body.getContentType())
throws MessagingException
{
String strSubject = "",temp="";
int pos = 0;
String strMailSubject[] = message.getHeader("Subject");
boolean flag = MailAccount.A;
String strCodingType = "";
if(strMailSubject == null)
{// System.out.println("邮件头空值,返回[没有主题]");
return subject;
}
else
{// System.out.println("原始长度 "+strMailSubject.length+" 内容 "+strMailSubject[0]);
if(strMailSubject[0].indexOf("=?GB_2312-80?") != -1)
strMailSubject[0] = StringUtil.replaceStr(strMailSubject[0], "=?GB_2312-80?", "=?GBK?");
try
{
if(strMailSubject[0].indexOf("=?ISO-8859-1?") != -1)
{
System.out.println("subject after decodeText =" + strMailSubject[0]);
strMailSubject[0] = new String(strMailSubject[0].getBytes("ISO-8859-1"));
}
else if(strMailSubject[0].indexOf("=?gb2312?") != -1)
{
strMailSubject[0] = new String(strMailSubject[0].getBytes("gb2312"));
}
else if(strMailSubject[0].indexOf("=?GB2312?") != -1)
{
strMailSubject[0] = new String(strMailSubject[0].getBytes("gb2312"));
}
else if(strMailSubject[0].indexOf("=?GBK?") != -1)
{
strMailSubject[0] = new String(strMailSubject[0].getBytes("GBK"));
}
else if(strMailSubject[0].indexOf("=?big5?") != -1)
strMailSubject[0] = new String(strMailSubject[0].getBytes("big5"));
else
{//正常字符集:ISO8859_1-->gb2312;主题ISO-8859-1-->gb2312;ISO-8859-1-->GBK;
strMailSubject[0] = new String(strMailSubject[0].getBytes("ISO-8859-1"), "gb2312");
}
strMailSubject[0] = MimeUtility.decodeText(strMailSubject[0]);
}
catch(UnsupportedEncodingException unsupportedencodingexception)
{
unsupportedencodingexception.printStackTrace();
cat.error("UnsupportedEncoding", unsupportedencodingexception);
} } this.subject = strMailSubject[0];
if(subject == null)
subject = "";
return subject;
}