I have an MS Word document, as a BLOB in a database.
byte [] jack = ..//an MS WORD Document, read into a byte array
//When I retrieve it from the DB, as a byte [], and write it to disk, the
file is fine.
//However, if I convert the byte array, to string, then back to byte array,
//it will now be unreadable from from Word if I write it to disk
String tempstring=new String(jack);
jack=tempstring.getBytes();
Can anyone tell me why? I thought these last two lines were entirely
reciprocal? Thanks, Ike
Danno - 28 Nov 2006 02:32 GMT
> I have an MS Word document, as a BLOB in a database.
>
[quoted text clipped - 7 lines]
> String tempstring=new String(jack);
> jack=tempstring.getBytes();
Did you make sure that you are getting and setting the right encoding?
IOW,
byte[] myBytes = tempstring.getBytes("UTF-8");
String myString = new String(myBytes, "UTF-8");
Just a thought
Dale King - 29 Nov 2006 05:36 GMT
>>I have an MS Word document, as a BLOB in a database.
>>
[quoted text clipped - 9 lines]
>
> Did you make sure that you are getting and setting the right encoding?
Note he said the bytes were the contents of a M$ Word document. There is
no right encoding.

Signature
Dale King
Dale King - 28 Nov 2006 02:32 GMT
> I have an MS Word document, as a BLOB in a database.
>
[quoted text clipped - 10 lines]
> Can anyone tell me why? I thought these last two lines were entirely
> reciprocal? Thanks, Ike
Whether a conversion of arbitrary byte data to a String and back is
lossless depends on the character encoding. The default encoding on
Windoze is not lossless. Your example is using the default encoding.
While there is an encoding you could use that is lossless, the real
question is why do you want to convert it to a string since it is not
really a string? Why not convert it to a bitmap which is just as
nonsensical as converting it to a string?

Signature
Dale King