• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Charset and encoding to chinese

 
Mattias Ahlin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I want to print out a chinese character. This is the code I'm using, but it doesn't work. Any ideas why?
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By "doesn't work" I suppose you mean you aren't seeing Chinese characters on your console? That's almost certainly because your console's character set doesn't include any Chinese characters. Using a GUI with a font that can render Chinese characters would be more practical. In this case what I would expect is for the first test to show a question mark and the second test to show the character you used.

And by the way, code that converts characters to bytes and then back to characters is almost always to be avoided. It's easy to mess things up (which is what your first test does) and if you don't mess things up, you just do nothing (which is what your second test does).
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Typically when something "doesn't work", it's helpful to describe what actually does happen. In this case, what happens is that you get this output:

OK, I guess a578 is intended to represent two bytes of data? Not four characters? And the two bytes are intended to be interpreted using the Big5 charset? In the code you gave, putting the a578 in a String literal caused them to get interpreted as chars, not what you want. Try this instead:

Now this may work, or not. On my console I just get a ?, because my computer isn't configured to display Chinese chars on the console. I don't know about you. You may well want to find another way to display the data. One option is to use GUI components. Here's a very simple one:

If that doesn't display correctly, it means the correct fonts aren't installed on your system. Alternately, you could create an HTML page and view it in your browser. Hope that helps...
 
Mattias Ahlin
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is how I solved the problem:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic