java字符集转换 Big5 和 Unicode互转

来源:互联网 发布:iaas云计算架构 编辑:程序博客网 时间:2024/06/16 20:56
完整的代码如下
帮助
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* java字符集转换 Big5 和 Unicode互转
* 转换后的正常字型
*/
 
import java.io.*;
 
public class Big5Unicode{
 public static String big5ToUnicode(String s){
 try{
 return new String(s.getBytes("ISO8859_1"), "Big5");
 }
 catch (UnsupportedEncodingException uee){
 return s;
 }
 }
 
 public static String UnicodeTobig5(String s){
 try{
 
return new String(s.getBytes("Big5"), "ISO8859_1");
}
catch (UnsupportedEncodingException uee){
return s;
}
}
 
public static String toHexString(String s){
String str="";
for (int i=0; i<s.length(); i++){
int ch=(int)s.charAt(i);
String s4="0000"+Integer.toHexString(ch);
str=str+s4.substring(s4.length()-4)+" ";
}
return str;
}
}
注:文章系本人原创:发布于 <script type="text/javascript"><!--google_ad_client = "ca-pub-1944176156128447";/* csdn 横中 */google_ad_slot = "7877933139";google_ad_width = 468;google_ad_height = 60;//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>