Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

Byte Array to String & back corruption

Thread view: 
Ike - 28 Nov 2006 02:12 GMT
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



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.