Remove file from Apache using servlet
I'm uploading files using servlet my little code is like this:
ServletFileUpload servletFileUpload = new ServletFileUpload(new DiskFileItemFactory());
try {
fileItemsList = servletFileUpload.parseRequest(request);
} catch (FileUploadException ex) {
Logger.getLogger(iThink.class.getName()).log(Level.SEVERE, null, ex);
}
String optionalFileNa开发者_运维技巧me = "";
FileItem fileItem = null;
Iterator it = fileItemsList.iterator();
...
The file is uploaded to apache directory (\webapps\mysite\uploads\abd.zip). Uploading is working fine but I want to delete it.
Since you already got a list of FileItem
objects you can simply iterate over that list and call FileItem#delete on the items. Alternatively use File#delete from Java's standard library.
精彩评论