File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes file delete mistake Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "file delete mistake" Watch "file delete mistake" New topic
Author

file delete mistake

thejwal pavithran
Ranch Hand

Joined: Feb 11, 2012
Posts: 117




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: 18541
    
    8

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: 117
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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: file delete mistake
 
Similar Threads
FileIO
client hangs after getting data from server
Need some basic help with converting
Create .txt file
Urgent Need some basic help with converting