jQuery in Action, 3rd edition
The moose likes I/O and Streams and the fly likes about private void writeObject ( ObjectOutputStream os ) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "about private void writeObject ( ObjectOutputStream os )" Watch "about private void writeObject ( ObjectOutputStream os )" New topic

about private void writeObject ( ObjectOutputStream os )

Pradeep Bhat

Joined: Jan 12, 2008
Posts: 29
How do these methods work ?

The serialization and deserialization of the object works fine without private void writeObject ( ObjectOutputStream os ) / read object methods.
However when I add them , i get a run time error as

Exception in thread "main" java.io.IOException: No such file or directory at java.io.FileOutputStream.writeBytes(Native Method) at java.io.FileOutputStream.write(FileOutputStream.java:260) at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1682) at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1591) at java.io.ObjectOutputStream.writeNonProxyDesc(ObjectOutputStream.java:1173) at java.io.ObjectOutputStream.writeClassDesc(ObjectOutputStream.java:1127) at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1284) at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1079) at java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java:1398) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:305) at Chapter6.TestSerialize.main(TestSerialize.java:23)

Code :
Rob Spoor

Joined: Oct 27, 2005
Posts: 20080

Don't close the streams in those two methods.

While usually it is a good idea to close all your streams, you should do it at the right times. Usually, that is not in a method of which the stream is a parameter - you may want to write to the stream after the method has finished.

Safest is to close it in the same method as where it was opened, if possible. Not in methods called from that method.

And one final note: don't use .txt as your file extension. That suggest it is a text file which it definitely isn't. No extension at all, or .bin are more appropriate.
[ September 29, 2008: Message edited by: Rob Prime ]

How To Ask Questions How To Answer Questions
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: about private void writeObject ( ObjectOutputStream os )
It's not a secret anymore!