• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Counterpart to ObjecOutputStream#writeChars?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey!

I was wondering whether there is a counterpart to ObjectOutputStream#writeChars (String str) in ObjectInputStream? Something like ObjectInputStream#readChars (), however I couldn't find such a method in this class.

So my question is, how can I read a serialized String written with writeChars from ObjectInputStream?

Thanks!

Cheers,
Jay
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
writeChars() doesn't serialize a whole string; in particular, it doesn't write the length of the String. If you use this method, then you have to know that somehow (perhaps just by writing it to the stream first using writeInt().) Then to read the data in, you could read the int, create a char[], and then use a for loop to read each char and store it.

A lot easier to just use writeObject() or writeUTF().
 
reply
    Bookmark Topic Watch Topic
  • New Topic