• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

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: 15725
368
  • 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:
 
Don't MAKE me come back there with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic