java - How to delete a file after uploading using Struts 2? -
i able upload file using struts2, want drop specified directory don't know how delete.
here code:
public string execute(){ destpath = "/tmp/listfile"; try{ system.out.println("src file name: " + myfile); system.out.println("dst file name: " + myfilefilename); file destfile = new file(destpath, myfilefilename); fileutils.copyfile(myfile, destfile); filelist = listfiles.listallfiles("/tmp/listfile"); return "listfiles"; } catch(ioexception e) { e.printstacktrace(); return "error"; } }
if use apache commons io it's one-liner:
fileutils.deletedirectory(dir);
Comments
Post a Comment