java help: How do I convert a byte[] to a String.

aceO07

Diamond Member
Nov 6, 2000
4,491
0
76
I'm trying to convert an byte[] to a String. When I use byte.toString(), the length of the String is only 10 or 9. However, the byte[] is length 30k or more. What am I doing wrong?

bt.length = ~29k
bt.toString.length = 9... It doesn't make sense to me..
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
String s = new String( byte[] );

Some times it will have extra space on the ends, so you might want to do


String s = new String(byte[])
s = s.trim();
 

Cerebus451

Golden Member
Nov 30, 2000
1,425
0
76
Does your byte array contain only valid characters, or does it possibly contain null characters? If there are null characters, then the string created will stop at the first null.