Convert byte array to understandable String

Posted by Ender on Stack Overflow See other posts from Stack Overflow or by Ender
Published on 2010-04-16T15:22:44Z Indexed on 2010/04/16 21:53 UTC
Read the original article Hit count: 278

Filed under:
|
|
|
|

I have a program that handles byte arrays in Java, and now I would like to write this into a XML file. However, I am unsure as to how I can convert the following byte array into a sensible String to write to a file. Assuming that it was Unicode characters I attempted the following code:

String temp = new String(encodedBytes, "UTF-8");

Only to have the debugger show that the encodedBytes contain "\ufffd\ufffd ^\ufffd\ufffd-m\ufffd\ufffd\/ufffd \ufffd\ufffdIA\ufffd\ufffd". The String should contain a hash in alphanumerical format.

How would I turn the above String into a sensible String for output?

© Stack Overflow or respective owner

Related posts about java

Related posts about hashes