This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes String(byte[ ]) constructor Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String(byte[ ]) constructor" Watch "String(byte[ ]) constructor" New topic
Author

String(byte[ ]) constructor

Jessica Farnham
Greenhorn

Joined: Feb 12, 2001
Posts: 5
For an application I'm working on, I'm trying to convert a byte array to a String for storage in a database. I've been trying to use a constructor I found in the String class documentation: String(byte[]bytes, String encoding). My code is compiling and running with no errors, but the resulting String is always empty, even though I've confirmed through debugging code that the byte array definitely has data. I suspect that the problem may be related to the fact that some of the bytes are negative or in some way out-of-range for the encoding, but haven't been able to identify the exact problem. Does anybody know how to make this work?
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

I have never had to do that. this info from the API might be helpful(for the String you supply to the constructor).

Every implementation of the Java platform is required to support the following character encodings. Consult the release documentation for your implementation to see if any other encodings are supported.
US-ASCII Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set
ISO-8859-1 ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1
UTF-8 Eight-bit Unicode Transformation Format
UTF-16BE Sixteen-bit Unicode Transformation Format, big-endian byte order
UTF-16LE Sixteen-bit Unicode Transformation Format, little-endian byte order
UTF-16 Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either order accepted on input, big-endian used on output)


SCJP
Visit my download page
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String(byte[ ]) constructor
 
Similar Threads
Are the code pages in charsets.jar documented somewhere?
any chance to know the charset of a remote database?
Create image from byte array
Confusion creating String
Quick String to <char> Array Conversion