| Author |
file delete mistake
|
thejwal pavithran
Ranch Hand
Joined: Feb 11, 2012
Posts: 113
|
|
hi guys the above snippet is only a relevant part of the program..if a user presses 3 then some contents of a file are removed based on some conditions.
This portion works fine .
But the problem arises when an attempt is made to delete the same file in another function. The files which are made to go through the operations in case 3 dont get deleted in another function..is the closing of the streams not done properly? please help..
To make the same BufferedReader point to the beginning of a file, re initialization is done as below:
removalReader = new BufferedReader(new FileReader(contactBookName));
is this proper?
|
on job hunt
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
thejwal pavithran wrote:
To make the same BufferedReader point to the beginning of a file, re initialization is done as below:
removalReader = new BufferedReader(new FileReader(contactBookName));
is this proper?
But that isn't the same BufferedReader. It's a new one (that's what the "new" keyword means). And no, creating a new BufferedReader and a new FileReader on a file won't close any other BufferedReaders and FileReaders which also use that file.
|
 |
thejwal pavithran
Ranch Hand
Joined: Feb 11, 2012
Posts: 113
|
|
Paul Clapham wrote:
thejwal pavithran wrote:
To make the same BufferedReader point to the beginning of a file, re initialization is done as below:
removalReader = new BufferedReader(new FileReader(contactBookName));
is this proper?
But that isn't the same BufferedReader. It's a new one (that's what the "new" keyword means). And no, creating a new BufferedReader and a new FileReader on a file won't close any other BufferedReaders and FileReaders which also use that file.
thank you for pointing that out...i forgot the basic concept of object reference here..sorted it out....so now i know that all streams related to a file have to be closed before file deletion...is there any such any other such conditions that have to be taken care of?
|
 |
 |
|
|
subject: file delete mistake
|
|
|