• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

byte[] to String

 
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 62
Ruby Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try this Byte Array to String
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

try this Byte Array to String


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.
reply
    Bookmark Topic Watch Topic
  • New Topic