File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes File Delete problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "File Delete problem" Watch "File Delete problem" New topic

File Delete problem

imran ghani

Joined: Dec 20, 2002
Posts: 1
i m trying to delete a file through my servlet
using the following code.
File file1 = new File(s);
boolean flag1 = file1.delete();
printwriter.println("Can't Delete " + s + "
return "false";
printwriter.println("deleted Successfully <br>");

s is a string variable containing path
s = "img/20-December-2002/101_heading.gif"
Alway's give me message can't delete file.Although file exists at this path.
Please give some solution...
Imran Ghani.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13027
The way you have expressed the path without a root implies that it is relative to the "current" directory, but in a servlet you have no control over the current directory.
Michael Bronshteyn
Ranch Hand

Joined: Mar 26, 2002
Posts: 85
make sure the user who runs servlet container has permission to delete the file ( write permission ).

Malhar Barai
Ranch Hand

Joined: Aug 17, 2001
Posts: 399
hi dear
i go with michael, check for the "Permission", i do create a lot of problem if not set properly.

Malhar Barai
SOA & Java Book
I agree. Here's the link:
subject: File Delete problem
It's not a secret anymore!