*
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
Author

File Delete problem

imran ghani
Greenhorn

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();
if(!flag1){
printwriter.println("Can't Delete " + s + "
<br>");
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
Rancher

Joined: Mar 22, 2000
Posts: 12760
    
    5
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.
Bill
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 ).


Michael
SCJP2
Malhar Barai
Author
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: http://aspose.com/file-tools
 
subject: File Delete problem
 
Similar Threads
Regarding File Download!!
Need urgent Help - Browser is hanging
how to transit the parameter ?
Uploading jpeg images to webserver
Java Plugin Problem 1.3.1_02