Solved

closing a FileReader / BufferReader

Posted on 2002-05-26
2
444 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 130 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …

724 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