[問題] 中文utf-8與big5互轉的問題

看板java作者 (瘋人院院長)時間15年前 (2008/12/07 12:58), 編輯推噓2(200)
留言2則, 1人參與, 最新討論串1/2 (看更多)
是這樣的 我需要把原本是 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

12/07 13:25, , 1F
拿char來測比較準 一個char是2-3 byte =.=a
12/07 13:25, 1F

12/07 13:27, , 2F
當我沒講 , 看起來沒有這麼單純~_~
12/07 13:27, 2F
文章代碼(AID): #19ErVyFI (java)
文章代碼(AID): #19ErVyFI (java)