Convert Java string to byte array
You used array.toString()
, which is implemented like this:
return "[B@" + Integer.toString(this.hashCode(), 16);
(In fact it inherits the definition from Object, and the part before the @
simply is the result of getClass().getName()
.)
And the hashCode here does not depend on the content.
Instead, use new String(array, encoding).
Of course, this only works for byte-arrays which are really representable as Java strings (which then contain readable characters), not for arbitrary arrays. There better use base64 like Bozho recommended (but make sure to use it on both sides of the channel).