JWorld@TW the best professional Java site in Taiwan
      註冊 | 登入 | 全文檢索 | 排行榜  

» JWorld@TW » Java SE 討論區  

按列印兼容模式列印這個話題 列印話題    把這個話題寄給朋友 寄給朋友   
reply to topicthreaded modego to previous topicgo to next topic
本主題所含的標籤
無標籤
作者 有關zhcode繁簡中文轉碼工具套件的使用問題 [精華]
liminjun

JavaDOCHelper真讚



發文: 496
積分: 5
於 2003-11-16 15:19 user profilesend a private message to usersend email to liminjunreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
zhcode繁簡中文轉碼工具套件的下載位置
http://www.mandarintools.com/zhcode.html

1.首先我去www.sina.com.cn的首頁用IE另存新檔成sina_gb.htm
2.我依照zhcode參數說明執行下面這個指令
1
2
3
4
java -cp zhcode.jar zhcode -bu sina_gb.htm temp.htm (都是亂碼)
java -cp zhcode.jar zhcode -gu sina_gb.htm temp.htm (自動顯示unicode簡體字)
java -cp zhcode.jar zhcode -gb sina_gb.htm temp.htm (手動切換gb顯示,繁體顯示不完整)
java -cp zhcode.jar zhcode -bg sina_gb.htm temp.htm (都是亂碼)

3.我發現轉碼出來的sina_big5.htm沒辦法正確顯示繁體中文(我有手動設定BIG5喔)

1
2
3
4
5
6
以下是zhcode參數的定義
g = GB2312, b = Big5, c = CNS11643, 8 = UTF-8, u = Unicode,
t = Unicode (traditional characters), h = HZ,
s = Unicode (simplified characters),
i = ISO-2022-CN, 2 = ISO-2022-CN-GB, n = ISO-2022-CN-CNS,
k = GBK


除此之外GB2312轉Unicode UTF-8 或是Big5轉Unicode UTF-8 都沒問題

麻煩曾經用過zhcode的大大詳細說明一下吧
請問這個套件有關繁簡互換的正確使用方法?


liminjun edited on 2003-11-17 00:01
reply to postreply to post
作者 Re:有關zhcode繁簡中文轉碼工具套件的使用問題 [Re:liminjun]
liminjun

JavaDOCHelper真讚



發文: 496
積分: 5
於 2003-11-16 20:15 user profilesend a private message to usersend email to liminjunreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
以下是我測試用的servlet,使用zhcode類別,可以正確編譯成功

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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
Sample359.java
 
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.lang.*;
import java.util.*;
 
class Encoding {
    // Supported Encoding Types
    public static int GB2312        = 0;
    public static int GBK           = 1;
    public static int HZ            = 2;
    public static int BIG5          = 3;
    public static int CNS11643      = 4;
    public static int UTF8          = 5;
    public static int UNICODE       = 6;
    public static int UNICODET      = 7;
    public static int UNICODES      = 8;
    public static int ISO2022CN     = 9;
    public static int ISO2022CN_CNS = 10;
    public static int ISO2022CN_GB  = 11;
 
    public static int ASCII         = 12;
    public static int OTHER         = 13;
 
    public static int TOTALTYPES    = 14;
 
    // Names of the encodings as understood by Java
    public static String[] javaname;
    // Names of the encodings for human viewing
    public static String[] nicename;
    // Names of charsets as used in charset parameter of HTML Meta tag
    public static String[] htmlname;
 
    // Constructor
    public Encoding() {
  javaname = new String[TOTALTYPES];
  nicename = new String[TOTALTYPES];
  htmlname = new String[TOTALTYPES];
 
  // Assign encoding names
  javaname[GB2312] = "GB2312";
  javaname[HZ] = "ASCII";  // What to put here?  Sun doesn't support HZ
  javaname[GBK] = "GBK";
  javaname[ISO2022CN_GB] = "ISO2022CN_GB";
  javaname[BIG5] = "BIG5";
  javaname[CNS11643] = "EUC-TW";
  javaname[ISO2022CN_CNS] = "ISO2022CN_CNS";
  javaname[ISO2022CN] = "ISO2022CN";
  javaname[UTF8] = "UTF8";
  javaname[UNICODE] = "Unicode";
  javaname[UNICODET] = "Unicode";
  javaname[UNICODES] = "Unicode";
  javaname[ASCII] = "ASCII";
  javaname[OTHER] = "ISO8859_1";
 
  // Assign encoding names
  htmlname[GB2312] = "GB2312";
  htmlname[HZ] = "HZ-GB-2312";  
  htmlname[GBK] = "GB2312";
  htmlname[ISO2022CN_GB] = "ISO-2022-CN-EXT";
  htmlname[BIG5] = "BIG5";
  htmlname[CNS11643] = "EUC-TW";
  htmlname[ISO2022CN_CNS] = "ISO-2022-CN-EXT";
  htmlname[ISO2022CN] = "ISO-2022-CN";
  htmlname[UTF8] = "UTF-8";
  htmlname[UNICODE] = "UTF-16";
  htmlname[UNICODET] = "UTF-16";
  htmlname[UNICODES] = "UTF-16";
  htmlname[ASCII] = "ASCII";
  htmlname[OTHER] = "ISO8859-1";
 
  // Assign Human readable names
  nicename[GB2312] = "GB-2312";
  nicename[HZ] = "HZ";
  nicename[GBK] = "GBK";
  nicename[ISO2022CN_GB] = "ISO2022CN-GB";
  nicename[BIG5] = "Big5";
  nicename[CNS11643] = "CNS11643";
  nicename[ISO2022CN_CNS] = "ISO2022CN-CNS";
  nicename[ISO2022CN] = "ISO2022 CN";
  nicename[UTF8] = "UTF-8";
  nicename[UNICODE] = "Unicode";
  nicename[UNICODET] = "Unicode (Trad)";
  nicename[UNICODES] = "Unicode (Simp)";
  nicename[ASCII] = "ASCII";
  nicename[OTHER] = "OTHER";
 
    }
 
    /*    System.out.println("Usage:  java zhcode -[gbc8ui2nk][gbc8uts2nk] in_file out_file");
     System.out.println("  g = GB2312, b = Big5, c = CNS11643, 8 = UTF-8, u = Unicode,");
     System.out.println("  t = Unicode (traditional characters),");
    System.out.println("  s = Unicode (simplified characters),");
     System.out.println("  i = ISO-2022-CN, 2 = ISO-2022-CN-GB, n = ISO-2022-CN-CNS,");
     System.out.println("  k = GBK");
    */
    
}
 
class zhcode extends Encoding {
    // Simplfied/Traditional character equivalence hashes
    protected Hashtable s2thash, t2shash;
 
    // Constructor
    public zhcode() {
  super();
  String dataline;
 
  // Initialize and load in the simplified/traditional character hashses
  s2thash = new Hashtable();
  t2shash = new Hashtable();
 
  try {
      InputStream pydata = getClass().getResourceAsStream("hcutf8.txt");
      BufferedReader in = new BufferedReader(new InputStreamReader(pydata, "UTF8"));
      while ((dataline = in.readLine()) != null) {
    // Skip empty and commented lines
    if (dataline.length() == 0 || dataline.charAt(0) == '#') {
        continue;
    }
    
    // Simplified to Traditional, (one to many, but pick only one)
    s2thash.put(dataline.substring(0,1).intern(), dataline.substring(1,2));
 
    // Traditional to Simplified, (many to one)
    for (int i = 1; i < dataline.length(); i++) {
        t2shash.put(dataline.substring(i,i+1).intern(), dataline.substring(0,1));
    }
      }
  }
  catch (Exception e) {
      System.err.println( e );
  }
 
    }
 
    public String convertString(String dataline, int source_encoding, int target_encoding) {
  StringBuffer outline = new StringBuffer();
  int lineindex;
  
  if (source_encoding == HZ) {
      dataline = hz2gb(dataline);
  }
  for (lineindex = 0; lineindex < dataline.length(); lineindex++) {
      if ((source_encoding == GB2312 || source_encoding == GBK || source_encoding == ISO2022CN_GB ||
     source_encoding == HZ || 
     source_encoding == UNICODE || source_encoding == UNICODES || source_encoding == UTF8) 
    &&
    (target_encoding == BIG5 || target_encoding == CNS11643 || target_encoding == UNICODET ||
     target_encoding == ISO2022CN_CNS)) {
    if (s2thash.containsKey(dataline.substring(lineindex, lineindex+1)) == true) {
        outline.append(s2thash.get(dataline.substring(lineindex, lineindex+1).intern()));
    } else {
        outline.append(dataline.substring(lineindex, lineindex+1));
    }
      } else if ((source_encoding == BIG5 || source_encoding == CNS11643 || source_encoding == UNICODET ||
      source_encoding == UTF8 ||
      source_encoding == ISO2022CN_CNS || source_encoding == GBK || source_encoding == UNICODE) 
           &&
           (target_encoding == GB2312 || target_encoding == UNICODES || target_encoding == ISO2022CN_GB ||
      target_encoding == HZ)) {
    if (t2shash.containsKey(dataline.substring(lineindex, lineindex+1)) == true) {
        outline.append(t2shash.get(dataline.substring(lineindex, lineindex+1).intern()));
    } else {
        outline.append(dataline.substring(lineindex, lineindex+1));
    }
      } else {
    outline.append(dataline.substring(lineindex, lineindex+1));
      }
  }
 
  if (target_encoding == HZ) {
      // Convert to look like HZ
      return gb2hz(outline.toString());
  }
 
  return outline.toString();
    }
 
    public String hz2gb(String hzstring) {
  byte[] hzbytes = new byte[2];
  byte[] gbchar = new byte[2];
  int byteindex = 0;
  StringBuffer gbstring = new StringBuffer("");
 
  try {
      hzbytes = hzstring.getBytes("8859_1");
  } 
  catch (Exception usee) { System.err.println("Exception " + usee.toString()); return hzstring; } 
 
  // Convert to look like equivalent Unicode of GB
  for (byteindex = 0; byteindex < hzbytes.length; byteindex++) {
      if (hzbytes[byteindex] == 0x7e) {
    if (hzbytes[byteindex+1] == 0x7b) {
        byteindex+=2;
        while (byteindex < hzbytes.length) {
      if (hzbytes[byteindex] == 0x7e && hzbytes[byteindex+1] == 0x7d) {
          byteindex++;
          break;
      } else if (hzbytes[byteindex] == 0x0a || hzbytes[byteindex] == 0x0d) {
          gbstring.append((char)hzbytes[byteindex]);
          break;
      }
      gbchar[0] = (byte)(hzbytes[byteindex] + 0x80);
      gbchar[1] = (byte)(hzbytes[byteindex+1] + 0x80);
      try {
          gbstring.append(new String(gbchar, "GB2312"));
      }  catch (Exception usee) { System.err.println("Exception " + usee.toString()); } 
      byteindex+=2;
        } 
    } else if (hzbytes[byteindex+1] == 0x7e) { // ~~ becomes ~
        gbstring.append('~');
    } else {  // false alarm
        gbstring.append((char)hzbytes[byteindex]);  
    }
      } else {
    gbstring.append((char)hzbytes[byteindex]);
      }
  }
  return gbstring.toString();
    }
 
    public String gb2hz(String gbstring) {
  StringBuffer hzbuffer;
  byte[] gbbytes = new byte[2];
  int i;
  boolean terminated = false;
 
  hzbuffer = new StringBuffer("");
  try {
      gbbytes = gbstring.getBytes("GB2312");
  }
  catch (Exception usee) { System.err.println(usee.toString()); return gbstring; }
 
  for (i = 0; i < gbbytes.length; i++) {
      if (gbbytes[i] < 0) {
    hzbuffer.append("~{");
    terminated = false;
    while (i < gbbytes.length) {
        if (gbbytes[i] == 0x0a || gbbytes[i] == 0x0d) {
      hzbuffer.append("~}" + (char)gbbytes[i]);
      terminated = true;
      break;
        } else if (gbbytes[i] >= 0) {
      hzbuffer.append("~}" + (char)gbbytes[i]);
      terminated = true;
      break;
        }
        hzbuffer.append((char)(gbbytes[i] + 256 - 0x80));
        hzbuffer.append((char)(gbbytes[i+1] + 256 - 0x80));
        i+=2;        
    }
    if (terminated == false) {
        hzbuffer.append("~}");
    }
      } else {
    if (gbbytes[i] == 0x7e) {
        hzbuffer.append("~~");
    } else {
        hzbuffer.append((char)gbbytes[i]);
    }
      }
  }
  return new String(hzbuffer);
    }
 
}
 
public class Sample359 extends HttpServlet {
  public void doGet(HttpServletRequest req,HttpServletResponse res)
  throws IOException, ServletException {
    res.setContentType("text/html; charset=big5");
    PrintWriter out = res.getWriter();
    
    
    String word = "繁體中文轉簡體中文測試";
    zhcode mycode = new zhcode();
    String Big5ToGb = mycode.convertString(word,mycode.BIG5,mycode.GB2312);
    
    
    
    out.println("<html><head>");
    out.println("<title>Servlet!</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("word =>"+word);
    out.println("<br>");
    out.println("convert word =>"+Big5ToGb);
    out.println("<br>");
    out.println("<h1>Java Servlet!</h1>");
    out.println("</body></html>");
    
 
    /*
    zhcode mycode=new zhcode(); 
    //繁體轉簡體 
    String Big5ToGb=mycode.convertString("繁體轉簡體",mycode.BIG5,mycode.GB2312); 
    */
 
  }
}


但是放在伺服器之後,開啟IE卻出現以下的錯誤訊息
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
HTTP Status 500 - 
 
--------------------------------------------------------------------------------
 
type Exception report
 
message 
 
description The server encountered an internal error () that prevented it from fulfilling this request.
 
exception 
 
javax.servlet.ServletException: Invoker service() exception
  org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:524)
  org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
 
root cause 
 
java.lang.NoClassDefFoundError: zhcode  <<Sample359.java已經有包含這個CLASS為什麼還會有這種錯誤訊息?
  Sample359.doGet(Sample359.java:292)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
  org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:466)
  org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:743)
  javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
 
note The full stack trace of the root cause is available in the Tomcat logs.
 
--------------------------------------------------------------------------------
 
Apache Tomcat/5.0.14


請問這是什麼原因造成的?該如何解決?
如果把紅色部分的程式碼去掉可以正常執行,所以問題可能是出在zhcode
but 是什麼問題呢?
如果把servlet部分去掉改寫成public static void main(String argc[]) {...}這種client的JAVA程式又可以正常執行...

真的頭暈了 不知道該怎麼處理
麻煩有使用過zhcode繁簡轉碼的大大分享一下使用經驗和方法

以上Sample359.java程式碼可以正確編譯,附加一個hcutf8.txt繁簡對照表也要下載
我使用WINXP+TOMCAT5


hcutf8.txt (53.43k)


liminjun edited on 2003-11-16 20:27
reply to postreply to post
作者 Re:有關zhcode繁簡中文轉碼工具套件的使用問題 [Re:liminjun]
Duncan

還隱隱作痛

版主

發文: 7816
積分: 39
於 2003-11-16 21:38 user profilesend a private message to usersend email to Duncanreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
你在部署 Sample359 這個 servlet 的時候有沒有設定好?要把 zhcode.class 一起部署上去。

reply to postreply to post

給我
辣味豆腐 其餘免談
作者 Re:有關zhcode繁簡中文轉碼工具套件的使用問題 [Re:Duncan]
liminjun

JavaDOCHelper真讚



發文: 496
積分: 5
於 2003-11-16 22:46 user profilesend a private message to usersend email to liminjunreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Duncan wrote:
你在部署 Sample359 這個 servlet 的時候有沒有設定好?要把 zhcode.class 一起部署上去。


這隻servlet是另外寫的獨立程式,跟原本的zhcode.class無關
因為我直接把所有相關CLASS都放置到Sample359檔案中了
您可以直接把上面的程式碼COPY下來編譯就知道了

如果是原始的zhcode程式RUN的話,繁簡轉換會出現問題,unicode則不會
不知道為什麼會這樣? 可否請有用過的人解答一下


reply to postreply to post
作者 Re:有關zhcode繁簡中文轉碼工具套件的使用問題 [Re:liminjun]
Duncan

還隱隱作痛

版主

發文: 7816
積分: 39
於 2003-11-16 22:53 user profilesend a private message to usersend email to Duncanreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
liminjun wrote:
這隻servlet是另外寫的獨立程式,跟原本的zhcode.class無關
因為我直接把所有相關CLASS都放置到Sample359檔案中了
您可以直接把上面的程式碼COPY下來編譯就知道了


你把所有的 class definition 放在一個 source file(Sample359.java)裡,編譯後還是會產生數個 .class files(一個類別一個),而不是 Sample359.class 檔就包括了一切東西。


reply to postreply to post

給我
辣味豆腐 其餘免談
作者 Re:有關zhcode繁簡中文轉碼工具套件的使用問題 [Re:Duncan]
liminjun

JavaDOCHelper真讚



發文: 496
積分: 5
於 2003-11-16 23:08 user profilesend a private message to usersend email to liminjunreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Duncan wrote:
你把所有的 class definition 放在一個 source file(Sample359.java)裡,編譯後還是會產生數個 .class files(一個類別一個),而不是 Sample359.class 檔就包括了一切東西。


感謝您提供這個極為重要資訊
我以為跟C編譯出來的程式一樣....抱歉了沒注意到

這個程式可以RUN了
剩下的問題就是
簡體(GB2312) <=> 繁體(Big5) 轉出來的字串似乎不正確
可否提供一下正確使用方法?

您直接下載原版zhcode執行網頁轉檔就知道問題所在了
繁簡互轉 沒有完整的正確


reply to postreply to post
作者 Re:有關zhcode繁簡中文轉碼工具套件的使用問題 [Re:liminjun]
liminjun

JavaDOCHelper真讚



發文: 496
積分: 5
於 2003-11-17 08:09 user profilesend a private message to usersend email to liminjunreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
以下這個部分稍作修改就能正確顯示出簡體和繁體中文了
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
public class Sample359 extends HttpServlet {
  public void doGet(HttpServletRequest req,HttpServletResponse res)
  throws IOException, ServletException {
    res.setContentType("text/html; charset=UNICODE");    //GB2312也可以正確顯示簡體   
   PrintWriter out = res.getWriter();
    
    
    String word = new String("繁體中文轉簡體中文測試");
    zhcode mycode = new zhcode();
    
    String Big5ToGb =mycode.convertString(word,mycode.BIG5,mycode.GB2312);
    //String Big5ToGb =mycode.convertString(word,mycode.GB2312,mycode.UNICODE);
    
    
    
    out.println("<html><head>");
    out.println("<title>Servlet!</title>");
    out.println("</head>");
    out.println("<body>");
    out.println("word =>"+word);
    out.println("<br>");
    out.println("convert word =>"+Big5ToGb);
    out.println("<br>");
    out.println("<h1>Java Servlet!</h1>");
    out.println("</body></html>");
    
 
  }
}


這個程式可以RUN了,繁簡轉換系統算是告一段落


liminjun edited on 2003-11-17 08:15
reply to postreply to post
作者 Re:有關zhcode繁簡中文轉碼工具套件的使用問題 [Re:liminjun]
chuang5089





發文: 254
積分: 0
於 2004-02-11 21:30 user profilesend a private message to usersend email to chuang5089reply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Why

when i use that code output
it become some as it before

zhcode mycode = new zhcode();
String word = new String("繁體中文轉簡體中文測試");
System.out.print(word+"\n");
String Big5ToGb =mycode.convertString(word,mycode.BIG5,mycode.GB2312);
System.out.print(Big5ToGb);

//----output
繁體中文轉簡體中文測試
繁體中文轉簡體中文測試


reply to postreply to post
作者 Re:有關zhcode繁簡中文轉碼工具套件的使用問題 [Re:chuang5089]
liminjun

JavaDOCHelper真讚



發文: 496
積分: 5
於 2004-02-11 21:38 user profilesend a private message to usersend email to liminjunreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
chuang5089 wrote:
Why

when i use that code output
it become some as it before

zhcode mycode = new zhcode();
String word = new String("繁體中文轉簡體中文測試");
System.out.print(word+"\n");
String Big5ToGb =mycode.convertString(word,mycode.BIG5,mycode.GB2312);
System.out.print(Big5ToGb);

//----output
繁體中文轉簡體中文測試
繁體中文轉簡體中文測試


麻煩檢查一下字典檔 hcutf8.txt 放置位置是否正確,這點不會顯示錯誤訊息,但是會造成沒辦法正確轉換,


liminjun edited on 2004-02-11 21:45
reply to postreply to post
作者 Re:有關zhcode繁簡中文轉碼工具套件的使用問題 [Re:liminjun]
chuang5089





發文: 254
積分: 0
於 2004-02-12 21:57 user profilesend a private message to usersend email to chuang5089reply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
Yes some of word does make chage in my program and then i would like to know how to fix this problem

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
import java.io.*;
import java.util.Hashtable;
 
public class China{
 
  public static void main(String args[]){
  
 
    String word = new String("繁體中文轉簡體中文測試");    
    
    zhcode mycode = new zhcode();  
    
        //mycode.convertFile("a.txt","c.txt",mycode.GB2312,mycode.BIG5);    
  
    System.out.println(word);
    String Big5ToGb =mycode.convertString(word,mycode.BIG5,mycode.GB2312);
 
    System.out.println(Big5ToGb);
 
    /*
      String str = Big5ToGb;
    byte [] barry = str.getBytes();
    FileOutputStream fo = new FileOutputStream("b.txt");
    for(int i = 0; i <barry.length; i++){
      fo.write(barry[i]);
    }
    fo.close();
    */
    
  
}
}


outpupt

繁體中文轉簡體中文測試
繁体中文??体中文??


browser edited on 2004-02-12 22:08
reply to postreply to post
作者 Re:有關zhcode繁簡中文轉碼工具套件的使用問題 [Re:chuang5089]
liminjun

JavaDOCHelper真讚



發文: 496
積分: 5
於 2004-02-13 00:52 user profilesend a private message to usersend email to liminjunreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
chuang5089 wrote:
Yes some of word does make chage in my program and then i would like to know how to fix this problem

outpupt

繁體中文轉簡體中文測試
繁体中文??体中文??


此問題和 Zhcode 套件無關,全是因為作業系統語系支援的問題
繁體中文 windows 的MSDos Console 模式,簡體字顯示問題,您可以安裝系統的簡體語系支援 還有 設定成簡體字字型


reply to postreply to post
作者 Re:有關zhcode繁簡中文轉碼工具套件的使用問題 [Re:liminjun]
ying0515





發文: 11
積分: 0
於 2008-02-21 18:27 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
請問
InputStream pydata = getClass().getResourceAsStream("hcutf8.txt");
如何指定d:\work\source\hcutf8.txt路徑??


reply to postreply to post
作者 Re:有關zhcode繁簡中文轉碼工具套件的使用問題 [Re:liminjun]
ying0515





發文: 11
積分: 0
於 2008-02-22 15:26 user profilesend a private message to userreply to postreply to postsearch all posts byselect and copy to clipboard. 
ie only, sorry for netscape users:-)add this post to my favorite list
以解決!

reply to postreply to post
» JWorld@TW »  Java SE 討論區

reply to topicthreaded modego to previous topicgo to next topic
  已讀文章
  新的文章
  被刪除的文章
Jump to the top of page

JWorld@TW 本站商標資訊

Powered by Powerful JuteForum® Version Jute 1.5.8