• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

file delete mistake

 
thejwal pavithran
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




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?
 
Paul Clapham
Sheriff
Posts: 21322
32
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic