Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Reg :UTF 8

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hai All,

When i execute the following program i am getting this out put.

Output : Activité?i?

code :




Characters " ź " and " ń" is not printing.
"?" is replaced for those characters.
Can you please help me to solve this.

Advance thanks,
Ram Kumar
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where are you printing this - to a console of some kind? Most (all?) consoles can't handle the full range of Unicode characters.
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that you aren't using UTF-8. You're using the system default encoding, which doesn't support those two characters. There are four parts to the problem: (1) You have to save the source file in an encoding that supports those characters. (2) You have to tell the compiler to read the source file with the same encoding. (3) When you write the output, you have to specify an appropriate encoding. (4) If you're writing to the console, you have to tell it to use the same encoding; if you write to a file, you have to make sure the editor you use to read the file uses the right encoding.

You can eliminate the first two parts of the problem by using Unicode escapes for any non-ASCII characters: As for the other two parts, the easiest solution is to avoid the console; it's too difficult to work with and too system-dependent. Just write to a file and specify the correct encoding: You can then read the result with any reasonably good editor (but try to avoid Windows Notepad).
 
chennai Kumar
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks I got the output.

 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic