File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes new String(byte[]) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "new String(byte[])" Watch "new String(byte[])" New topic

new String(byte[])

Kejal Shah
Ranch Hand

Joined: Jun 27, 2003
Posts: 87
I pass a byte array to create a new String object. However, the byte representation of this new string is different from the one I pass it.

One of the bytes in the passed byte array is 0x90 or 144. However, in the string object tat i retrieve, this byte is 63!

Tx in adv
[ February 23, 2005: Message edited by: Kejal Shah ]

Kejal<br />
Joe Ess

Joined: Oct 29, 2001
Posts: 9189

A String is supposed to represent characters, not the full range of the char data type. I would wager that the value you are attempting to set cannot be represented in your default charset so it gets substituted. For further info, read up on java.nio.charset.Charset and look up your local Unicode code chart

[How To Ask Questions On JavaRanch]
I agree. Here's the link:
subject: new String(byte[])
It's not a secret anymore!