Re: Java String to integer conversion not working
Daniel Pitts wrote:
On Mar 19, 3:53 pm, ashish.lo...@gmail.com wrote:
....
I used the above code segment and realized that before every integer
there was a null char
so the output being:
s[0] = 0 =
s[1] = 53 = 5
s[2] = 0 =
s[3] = 54 = 6
s[4] = 0 =
s[5] = 57 = 9
s[6] = 0 =
....
Sounds like you're not setting up the proper encoding for reading the
string. While your "fix" may be working now, you should use the
proper decoding by creating an InputStreamReader object, and passing
THAT to your BufferedReader object.
I reached the same general conclusion, but in the opposite direction,
superfluous decoding rather than missing decoding.
Suppose the file contained 569 as bytes, tab delimited, hex 09 35 36 39
09. Reading it as chars, omitting the byte to char conversion, would get
a char containing hex 3536 or 3639, which we don't see.
Now suppose the file contains char data, hex 0009 0035 0036 0039 0009,
and was read as a byte stream and passed through a byte to char decode,
such as InputStreamReader.
The result would be hex 0000 0009 0000 0035 0000 0036 0000 0039 0000
0009. There are now seven characters between the two instances of
horizontal tab, 0009, and those seven characters match the printout.
Patricia