Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

how to delete a file in java

807607Aug 18 2006 — edited Nov 23 2006
Hi,

I have a log file and this log file should be deleted when user clicks on a menu option.

Intially this file is opened using buffered reader as follows
 BufferedReader in=new BufferedReader(new FileReader(logFilePath)) 
log file is read and some logic goes here.

then buffered reader is closed as follows.
 finally {
			 try {
		        if (in!= null) {
		          //flush and close both "input" and its underlying FileReader
		          System.out.println("Stream has been closed"); 	
		          in.close();
		        }
		      }
		      catch (IOException ex) {
		        ex.printStackTrace();
		      }
		    }
then when the user tries to delete the file, it's saying that the file can't be deleted.

Is there any problem in closing the file before deleting the file?

Can any one suggest me a way to do this.

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 21 2006
Added on Aug 18 2006
8 comments
414 views