Hi All
Thanx for giving ur invaluable time to my question.
I hv given a facility to a site user to upload some files..
And an interface to web administrator to view all the files..
I want to know how can i write a code in JSP which allow the web administrator to delete any of that file which is not of his/her interest through provided interface only.
OR
Is is possible to delete a particular file from web server without getting login into FTP account
Thanx
Discussions
Web tier: servlets, JSP, Web frameworks: How to delete a File from web-server without using FTP
-
How to delete a File from web-server without using FTP (1 messages)
- Posted by: Ravi Dua
- Posted on: March 20 2002 02:08 EST
Threaded Messages (1)
- How to delete a File from web-server without using FTP by joseph yi on March 20 2002 13:12 EST
-
How to delete a File from web-server without using FTP[ Go to top ]
- Posted by: joseph yi
- Posted on: March 20 2002 13:12 EST
- in response to Ravi Dua
// choose the appropriate filepath
// you can also use File.separator for your slashes
// if you are building a dynamic path
// win32,dos
String filePath = "c:\\tomcat\\webapps\\myapp
myfile.txt";
// unix,linux,etc
String filePath = "/usr/local/tomcat/webapps/myapp/myfile.txt";
// code to delete file :p
File f = new File(filePath);
if(f.exists()) {
f.delete();
}
// yes it's that easy...
so if you already have a listing of files, simply provide a URL link to each file or a form listing and then have it go to your controller... so you can have:
File f = new File(request.getParameter("filePath");
or build a dynamic file path
String filePath = getServletContext().getRealPath("") + File.separator + "WEB-INF" + File.separator + "uploads" + File.separator + request.getParameter("fileName");
I think you get my drift... but the code to delete is simple...