Solved

closing a FileReader / BufferReader

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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What's wrong with this code? 4 36
How  can  i  resolve  HTTP Status 404 -? 8 61
JAVA API design with micro service cloud in mind 1 82
Bot application - advice 3 64
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
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 …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

730 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