aspose file tools*
The moose likes Java in General and the fly likes Charset and encoding to chinese Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Charset and encoding to chinese" Watch "Charset and encoding to chinese" New topic
Author

Charset and encoding to chinese

Mattias Ahlin
Greenhorn

Joined: May 31, 2006
Posts: 11
Hi

I want to print out a chinese character. This is the code I'm using, but it doesn't work. Any ideas why?


Best regards,<br />Mattias
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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

Joined: Jan 30, 2000
Posts: 18671
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...


"I'm not back." - Bill Harding, Twister
Mattias Ahlin
Greenhorn

Joined: May 31, 2006
Posts: 11
This is how I solved the problem:
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Charset and encoding to chinese