Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

about private void writeObject ( ObjectOutputStream os )

 
Pradeep Bhat
Greenhorn
Posts: 29
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Pie
Posts: 20386
46
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic