• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Charset and encoding to chinese

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 28263
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is how I solved the problem:
 
reply
    Bookmark Topic Watch Topic
  • New Topic