/**
* 将UNICODE8编码的字符串转化为GB2312编码。
*
*@param source Description of the Parameter
*@return 转换后可在网页上正常显示的字符串。
*/
public final static String utf8ToGb2312( String source )
{
return translate( source, "iso-8859-1", "GBK" );
} /**
* 转化源编码的字符串为目标编码。
*
*@param source Description of the Parameter
*@param sourceCodeset Description of the Parameter
*@param targetCodeset Description of the Parameter
*@return java.lang.String
*/
public final static String translate( String source, String sourceCodeset,
String targetCodeset )
{
String out; try
{
out = new String( source.getBytes( sourceCodeset ), targetCodeset );
}
catch ( Exception ex )
{
out = "";
} return out;
} /**
* 将GB2312编码的字符串转化为UNICODE8编码。
*
*@param source Description of the Parameter
*@return Java内码表示的字符串。
*/
public final static String gb2312ToUtf8( String source )
{
return translate( source, "GBK", "iso-8859-1" );
}
* 将UNICODE8编码的字符串转化为GB2312编码。
*
*@param source Description of the Parameter
*@return 转换后可在网页上正常显示的字符串。
*/
public final static String utf8ToGb2312( String source )
{
return translate( source, "iso-8859-1", "GBK" );
} /**
* 转化源编码的字符串为目标编码。
*
*@param source Description of the Parameter
*@param sourceCodeset Description of the Parameter
*@param targetCodeset Description of the Parameter
*@return java.lang.String
*/
public final static String translate( String source, String sourceCodeset,
String targetCodeset )
{
String out; try
{
out = new String( source.getBytes( sourceCodeset ), targetCodeset );
}
catch ( Exception ex )
{
out = "";
} return out;
} /**
* 将GB2312编码的字符串转化为UNICODE8编码。
*
*@param source Description of the Parameter
*@return Java内码表示的字符串。
*/
public final static String gb2312ToUtf8( String source )
{
return translate( source, "GBK", "iso-8859-1" );
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货