File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 4347
    
    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
 
Consider Paul's rocket mass heater.
 
subject: String(byte[ ]) constructor