中文问题应该到处都一样,你可以这样试试
public static final String toCNString( String str ) {
if ( str == null ) {
return null;
}
try {
byte[] bt = str.getBytes( "ISO8859-1" );
str = new String( bt, "GB2312" );
}
catch ( Exception ex ) {
return null;
}
return str;
}
用上面的方法把邮件地址转一下。
public static final String toCNString( String str ) {
if ( str == null ) {
return null;
}
try {
byte[] bt = str.getBytes( "ISO8859-1" );
str = new String( bt, "GB2312" );
}
catch ( Exception ex ) {
return null;
}
return str;
}
用上面的方法把邮件地址转一下。
msg.addRecipient(Message.RecipientType.TO,addr);
.....http://www.javayou.com
{
public static void main(String[] args)
{
TestArray a = new TestArray();
System.out.println( a.toCNString( "中文abc" ) );
}
public static final String toCNString( String str ) {
if ( str == null ) {
return null;
}
try {
byte[] bt = str.getBytes( "ISO8859-1" );
str = new String( bt, "GB2312" );
}
catch ( Exception ex ) {
return null;
}
return str;
}
}输出是:
??abc
加了InternetAddress addr = new InternetAddress("[email protected]","Java自由人","GB2312");
就编译不通过
"mail.java": unreported exception java.io.UnsupportedEncodingException; must be caught or declared to be thrown at line 44, column 30
还有就是如果同时发多人怎么办呢
InternetAddress addr = new InternetAddress("[email protected]","Java自由人","GB2312");就编译不通过"mail.java": unreported exception java.io.UnsupportedEncodingException; must be caught or declared to be thrown at line 44, column 30try一下把异常捕捉了就可以了嘛
try{
InternetAddress addr = new InternetAddress("[email protected]","Java自由人","GB2312");
}catch(Exception e){}初学java啊?