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? Thanks s:vaPrasad Here is the code :
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 java.io 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.
"I'm not back." - Bill Harding, Twister
You get good luck from rubbing the belly of a tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss