wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes file Deletion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "file Deletion" Watch "file Deletion" New topic
Author

file Deletion

Kalyan Saha
Greenhorn

Joined: Oct 20, 2011
Posts: 5
File del=new File(dirName);
del.delete();

this code doesn't seem to be working.. dirName what should be passed pathname and the file of only the directory path? please suggest...

Kalyan
sri ramvaithiyanathan
Ranch Hand

Joined: Nov 20, 2010
Posts: 109
welcome to coderanch...

Pass path of the file name which you want to delete.
And make sure you have imported java.io.*;

Search google before asking any kind of question.


For java examples,ebooks,interview questions,visit this blog
http://periodicupdates.blogspot.com/
Kalyan Saha
Greenhorn

Joined: Oct 20, 2011
Posts: 5
I have tried earlier, these suggestion you have given. And searched Google also.
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287

Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
Note that File.delete returns a boolean that indicates whether the operation was successful; you should always check that and act on it appropriately.
Kalyan Saha
Greenhorn

Joined: Oct 20, 2011
Posts: 5
File.delete() is returning false every time.
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
And File.exists()?
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
And File.exists() returns true? If that's the case then it could be a permissions problem, or the file could be in use by some other process.
Kalyan Saha
Greenhorn

Joined: Oct 20, 2011
Posts: 5
Yes may be it is the tomcat.exe which is using the file.
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408


Well, it goes without saying that you should not delete any files that are part of Tomcat, or one of the web apps it runs.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19680
    
  19

And if it's a directory you will need to remove all files and sub directories in it first.

Also, if you have opened an InputStream / OutputStream / Reader / Writer to the file and haven't closed it (which you should do in a finally block, or preferably in Java 7 using try-with-resources) that will also prevent the file from being deleted.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Kalyan Saha
Greenhorn

Joined: Oct 20, 2011
Posts: 5
I was trying to delete those files because it is saved in the database as a binary format. Every time any view is made for the image files creates a .JPG file in that folder. So, these are being a dump amplifying application size.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: file Deletion