Java字符串编码转换UTF-8
2012-09-25 09:57
302 查看
import java.io.UnsupportedEncodingException; /** * * * 描述:<p> 功能描述,该部分必须以中文句号结尾。</p> * 创建日期:2012-7-16 下午4:28:16<br> * @author:tianyj<br> * @update:$Date$<br> * @version:$Revision$<br> * @since 版本号,用来指定该类是从整个项目的哪个版本开始加入到项目中的 */ public class ConvertCharSet { private static String changeCharSet( String str, String newCharset) throws UnsupportedEncodingException { if (str != null) { // 用默认字符编码解码字符串。 byte[] bs = str.getBytes(); // 用新的字符编码生成字符串 return new String(bs, newCharset); } return str; } /** * 字符串转化为UTF-8 * @param str * @return */ public static String toUTF8(String str){ String result = str; try { result = changeCharSet(str, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return result; } /** * 字节数组转化为UTF-8 * @param bty * @return */ public static String toUTF8(byte[] bty){ try { if (bty.length > 0) { return new String(bty, "UTF-8"); } } catch (UnsupportedEncodingException e) { e.printStackTrace(); } return new String(bty); } }
相关文章推荐
- Java字符串编码转换UTF-8
- 【JAVA编码】 JAVA字符编码系列二:Unicode,ISO-8859,GBK,UTF-8编码及相互转换
- 怎么把存储UTF-8编码的字符串转换成实际字符
- 关于JAVA字符编码:Unicode,ISO-8859-1,GBK,UTF-8编码及相互转换
- Java 中文字符串编码之GBK转UTF-8
- 将字符串转换成gb2312或者utf-8编码的参数(js版)
- java中字符串在 utf-8 gbk unicode 编码下占内存位数
- 将字符串的编码格式转换为utf-8
- java字符串的各种编码转换
- java字符串编码及转换
- java字符串编码转换
- 日期转换工具以及常用的字符,产生随机数,将java流中的编码转换为utf-8----java
- 【JAVA编码】 JAVA字符编码系列二:Unicode,ISO-8859,GBK,UTF-8编码及相互转换
- JS中文字符串和UTF-8编码字符串相互转换
- 将字符串转换成gb2312或者utf-8编码的参数(js版)
- java转换字符串的编码
- 【JAVA编码】 JAVA字符编码系列二:Unicode,ISO-8859,GBK,UTF-8编码及相互转换
- java怎样实现将GB2312编码的字符串转换为ISO-8859-1编码的字符串
- java实现utf-8与GB2312编码的转换
- 使用java的native2ascii工具命令来转换编码gbk,gb2312,utf-8【转】