?
Solved

closing a FileReader / BufferReader

Posted on 2002-05-26
2
Medium Priority
?
448 Views
Last Modified: 2010-08-05
Hi,

1. When using FileReader or BufferReader, do you must close the object?
2. What happens if the file remains open and there's no close call?

Thanks Kayzer.
0
Comment
Question by:kayzer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 7

Accepted Solution

by:
tomboshell earned 520 total points
ID: 7035202
As I see it, it is good programming practice.  The garbage collector takes care of variables when they are no longer used.  This is usually after the exit from a block of code (ie a function block or a sub-class, ect).  Then the gc may release the block of memory for the local and temp variables automatically.  However, if you readers are declared globally  then they will exist the entire time the program is running-thereby using up a lot of resources.  Leaving file pointers (readers or writers) running free you may incure read/write blocks.  If that happens you may wonder why some other code can't work with that file.  Also, what if you program grows extremely large?  Will you be able to find the proper spot to close the file again, thereby optimizing that area of code; at the same time, would others maintaining your code be capable of finding the open reader?  It is just better to close the readers.  
If you leave it open, at some time the program must be exited.  Then it will be closed by exiting the virtual machine.  If some other error or memory problem doesn't occur before hand.  
0
 
LVL 7

Expert Comment

by:tomboshell
ID: 7035458
Thanks for the grade!
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.
Suggested Courses
Course of the Month11 days, 8 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question