/**
* 将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" );
}
解决方案 »
- 使用ZipFile相关类读取txt文件不完全,求解决
- 小程序,最后一行总是报错,贴出来了,大家帮忙看看:)
- 快被折磨疯了!图片怎么都画不上去!高手帮忙!在线等!!!
- 新手上路 servlet过滤器问题,求高人指点,谢谢(顶)
- 在线等:接口中的方法和类中方法一样,当不指定存取类型时,都是默认的存取类型?
- 关于算术右移和逻辑右移
- 如何将unicode原始编码转化成它代表的字符,急!!!
- 关于JTextPane自动滚屏的问题。(up有分了)
- JDO和Entity Bean有什么区别?
- 哪兒下載java 2 SDK 1.3.1??
- help
- 测试一下这里是否有OO高手, 这是我贴在买买提bbs的一个小挑战的第一步, 没人能够给出令人满意的回答.
应该就没问题
Give me 分!
我对JAVA一窍不通啊!