• Post Reply Bookmark Topic Watch Topic
  • New Topic

byte[] to String  RSS feed

 
M Burke
Ranch Hand
Posts: 410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I found ByteToCharConverter. But it's depricated. What is the accepted practice to convert a byte array to a string of characters in Java 6? byte[].toString() does not convert the bytes to chars.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
M Burke wrote:Hi,
I found ByteToCharConverter. But it's depricated. What is the accepted practice to convert a byte array to a string of characters in Java 6? byte[].toString() does not convert the bytes to chars.



Not all of the constructors of the java.lang.String class are deprecated -- just the ones that didn't work very well are. I am sure one of the constructors / methods of the String class will work here.

Henry
 
Pierre Sugar
Ranch Hand
Posts: 62
Java Ruby Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try this Byte Array to String
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

That's works only if the contents of the array are encoded using the platform default encoding. Unless it's known in advance that that will always be the case, it's better to specify the encoding explicitly.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!