• 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

Object Output Stream

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Can some body help me how to write a method so that I can store object on a persistent stream. E.g. any text file.

I would like to use this method below: -

[/code]

If anybody has some examples please forward.
Thanks a lot.
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ronald Spina wrote:oos = newObjectOutputStream(fos);
out.writeObject();



Well, no, objects don't have names. You would pass a reference to the object you want to write. Since you already have some of the code, and obviously have an idea of what might be next, why not try it and see?

Note, however, that it will not be a text file. This is a binary format, not intended for human consumption. If you want something human readable (sort of), you could use java.beans.XMLEncoder/XMLDecoder.

If anybody has some examples please forward.



There's sure to be plenty on the web. Search for java serialization example or java writeObject example or even java io tutorial.

And welcome to the Ranch!
reply
    Bookmark Topic Watch Topic
  • New Topic