Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

writeObject OR writeUTF  RSS feed

 
hasan khan
Ranch Hand
Posts: 223
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have to write a String to ObjectOutput, which method do i use writeUTF or writeObject.

if both methods will give same result, then which one will be faster.
[ May 30, 2006: Message edited by: hasaN khaN ]
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you simple want to write the String to the underlying stream, then use writeUTF(), but if you are serializing the objects, not just the data, then use writeObject().

The writeObject() method will also save information related to the class and its current version, and will probably save additional information related to the objects state, not only its apparent value, for instance, it will serialize also the private state of the object.

While writeUTF() will simply transform your String into a array of bytes according to the UTF-8 charset and then will write those bytes to the underlying stream.

What do you want to do?
[ May 30, 2006: Message edited by: Edwin Dalorzo ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!