This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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

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: 12791
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
GeeCON Prague 2014
subject: File Delete problem