• 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

String encoding and decoding

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not able to print other language characters.
What could be the problem?
Sample code:



 
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where are you trying to print the characters? Is it somewhere that can handle umlauts and such?
 
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are possibly three things going wrong. The first is that you're not telling System.out what encoding you want to use to print. It doesn't matter if you've correctly stored the characters in a String, the output system still needs to know what encoding you want to print the data in.

The second problem is that even if your program prints in the encoding you want, the program that's receiving the data (probably the command prompt, or maybe your IDE console) may not expect this encoding, and interpret the data incorrectly.

The third problem is that even if the console understands exactly what character you want to print, its font does not have a graphical glyph to represent the character, and displays it with a surrogate instead.

I recommend you write a small GUI with a text area, that uses the MS Gothic font. Now try to append different characters to it.
 
Sajin Balakrishnan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
actually the problem in converting xml to excel.greek letters are stored in database which when read from database and exported in excel using below method.appears as ??? in excel

 
Stephan van Hulst
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sajin, please UseCodeTags when posting code. I have added them to your post, but remember to do it the next time.

Why are you using getBytes() all over the place?
 
Sajin Balakrishnan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok..beacuse i am writing it to a FileOutputSteam hence convertin it to bytes
 
Stephan van Hulst
Saloon Keeper
Posts: 15484
363
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is part of why your program doesn't work as intended. You should not mess around with the raw bytes. Instead, there are some great classes in the standard library that will make life easier for you.

Try using the following:
Now you will be able to simply write the String you want to the Writer, and it will encode it to the correct character set.
 
Sajin Balakrishnan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot Stephan , it worked.
 
All that thinking. Doesn't it hurt? What do you think about this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic