• 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

Java Encoding from UTF8 to BIG5 - Some of the characters are displayed as "?"

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

byte[] encoding1 = "康揚股份有限公司".getBytes("UTF-8");
String s1 = new String(encoding1,"BIG5");
System.out.println("String 1:"+s1);

String 1:摨瑟���∩遢�����砍��


While trying to change from UTF8 to Big5 some of the characters are displayed as "?"
I understand those characters are not present in the character set.
Is there any other option to generate in Traditional Chinese version ?
 
Saloon Keeper
Posts: 15510
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

You're not changing UTF-8 to Big5. You're encoding a String (which under the hood MAY use a combination of a byte array and an encoding, usually UTF-16) as UTF-8, and then interpreting your UTF-8 byte array as Big5, which obviously is not going to work.

Remember, String represent a sequence of characters, and character do not have an encoding. Characters can be encoded to a sequence of bytes, which DO have an encoding.

If you want to encode your string to Big5, all you have to do is "康揚股份有限公司".getBytes(Charset.forName("BIG5"));

If you want to change the encoding of an UTF-8 encoded String to Big5, you do:
 
A timing clock, fuse wire, high explosives and a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic