aspose file tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question about ObjectOutputStream close() method Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Question about ObjectOutputStream close() method" Watch "Question about ObjectOutputStream close() method" New topic
Author

Question about ObjectOutputStream close() method

Balraj Momi
Ranch Hand

Joined: Jul 23, 2009
Posts: 45

I know that close() method inside streams is to release all the resources that were used for a operation.
Question is what exactly are the side effect if we don't close it?
Following code does something like this


Please don't think silly of me by seeing "ObjectOutputStream stream" as static, I took it just to keep this Stream object alive for next write Operation. If you notice, First method call writeData() used text.txt file to write a object and did not close the stream. Later second method opened another stream to write to same file and so does the read operation. As far resources are concerned, should not we get IOException or something in this case.
Please do let me know If my assumption is wrong.
Regards
Balraj


Regards
Balraj Kumar
SCJP 5 95%
SCWCD 82%
Preparing for SCBCD
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
To your side-effects question.

If you do not close a stream to a resource or file, the underlying OS keeps a pointer to it that is used by the JVM.

You have probably experienced the Windows error message 'file could not be deleted because it is used by another process'.
This is one of the side effects.


JDBCSupport - An easy to use, light-weight JDBC framework -
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Question about ObjectOutputStream close() method
 
Similar Threads
Updating a file from an object (ArrayList)
Object serialization writeChars()
save state of variable
Object Serialization
HttpSession failure