Win a copy of TDD for a Shopping Website LiveProject this week in the Testing 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 ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Himai Minh

default encoding problems

Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'am facing a wierd problem. read on...
When I try to run the following code
I get different result with default encoding on both Unix and NT.
Can any one shed some light on this?
by the way I am restricted to use only Java 1.2.2
I know JDK1.3 and beyond JDK come with character encodings including UTF-16 etc..
My question is ...
why I see diff characters from getBytes() method for special characters in between 0-255?
Here is the code :

[ June 27, 2002: Message edited by: Siva Prasad ]
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1.2.2 has different encodings available as well. And the problem you see with default encodings exists in 1.3 and 1.4 as well. Basically, different platforms prefer to use different encodings by default. This way if you write a text file and the user tries to look at it with other tools on that plaform, like notepad or vi, they will have a better chance of reading the text without seeing "funny" characters. This works fine if you're just reading and writing files on that platform. But the moment you exchange data with other machines, you must consider the possibility that they will use a different encoding. Usually this is solved by choosing a particular encoding (like UTF-8) requiring (or at least hoping) that all applications accessing the data will use the same encoding. The package allows you several ways to specify an encoding. I usually use an InputStreamReader or OutputStreamWriter, and use one of the constructors that allows an encoding specification. E.g.
You get good luck from rubbing the belly of a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
    Bookmark Topic Watch Topic
  • New Topic