/**
* 将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 = "";
} //System.out.println(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 = "";
} //System.out.println(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" );
}
应该就没问题
Give me 分!
我对JAVA一窍不通啊!