作者plokijuh (疯人院院长)
看板java
标题[问题] 中文utf-8与big5互转的问题
时间Sun Dec 7 12:58:32 2008
是这样的
我需要把原本是 utf-8 的编码转成 big5 後 再转回 utf-8 的文字
结果我发现这样的互转会有问题
OS: Windows XP SP3
JDK: 1.6.0 update 11
IDE: Eclipse 3.4
Eclipse设定
Genel>Workspace: UTF-8
Project>Resource:UTF-8
import java.io.UnsupportedEncodingException;
public class TestRun {
public static void main(String[] args) throws UnsupportedEncodingException
{
String enc = System.getProperty("file.encoding");
System.out.println(enc);
String e = "中文转码测试";
String e5 = new String(e.getBytes("utf-8"),"big5");
String e8 = new String(e5.getBytes("big5"),"utf-8");
System.out.println(e);
byte y[]=e.getBytes("utf-8");
for (int i=0; i<y.length; i++) {
System.out.printf("%x ", y[i]);
}
System.out.println();
System.out.println(e5);
byte x[]=e5.getBytes("big5");
for (int i=0; i<x.length; i++) {
System.out.printf("%x ", x[i]);
}
System.out.println();
System.out.println(e8);
byte z[]=e8.getBytes("utf-8");
for (int i=0; i<z.length; i++) {
System.out.printf("%x ", z[i]);
}
}
}
结果原始的文字转成 big5 後转不回 utf-8
输出结果
utf-8
中文转码测试
e4 b8 ad e6 96 87 e8 bd 89 e7 a2 bc e6 b8 ac e8 a9 a6
????????????
e4 b8 ad e6 3f e8 bd 3f a2 bc e6 b8 ac e8 a9 a6
????????????
e4 b8 ad ef bf bd 3f ef bf bd 3f ef bf bd ef bf bd e6 b8 ac e8 a9 a6
不知道有人遇到过吗?
--
my blog
http://blog.cheyingwu.tw/
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 61.62.138.17
1F:推 TonyQ:拿char来测比较准 一个char是2-3 byte =.=a 12/07 13:25
2F:推 TonyQ:当我没讲 , 看起来没有这麽单纯~_~ 12/07 13:27