Forums Register Login

Convert byte[] to StringBuffer

+Pie Number of slices to send: Send
I've read a byte array from an open file stream and need to display the contents. It appears that



only prints the address (goop, in fact). Googling, I am unable to find a means of doing this. I have tried:



but this doesn't work. I guess I could resort to printing out the bytes one by one, but how fun is that?
+Pie Number of slices to send: Send
This should work:
+Pie Number of slices to send: Send
Thanks. That does it, of course.
+Pie Number of slices to send: Send
What String str = new String(bytes) does it to create a java String (i.e. UTF-16) using the default platform character encoding (for windows 2000 this is cp1252).

If the byte array was created from a string encoded in the platform default character encoding this will work well.

If not you need to specify the correct character encoding (Charset) as
String str = new String (byte [] bytes, Charset charset)
+Pie Number of slices to send: Send
Thanks very much. I only needed a quick way to get data read from FileInputStream.read() quickly out to System.out.println() for debugging purposes. However, knowing about the encoding problem will come in handy for a real application.
I think I'll just lie down here for a second. And ponder this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 16174 times.
Similar Threads
Files
How to use AES DECRYPT_MODE?
Receiving null value ?
FileInputStream & Negative Bytes...
Mock exam Question.Please anybody explain the output
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 06:25:30.