Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Edit/Delete Objects from file

 
Brian Cummins
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just wondering if there is any way of editing or deleting objects when they are read from a text file using the ObjectInputStream.
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once you've read the Object out of the stream, you can do whatever you want with it. Take a look at how this guy reads a Dimension object out of the stream:
http://home.tiscali.nl/~bmc88/java/sbook/041.html

At that point, he could fiddle with the Dimension object however he wanted to...it's in memory, just like all your other regular objects, so have at it!

Overview:
http://java.sun.com/j2se/1.4.2/docs/api/java/io/ObjectInputStream.html
 
Igor Stojanovic
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thx Stephen for posting that link.


P.S. Do you have more links in your bookmarks like the first one?


kind regards
Igor
 
Brian Cummins
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the advice. But can you actually overwrite that object in the file after editing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic