SSH Skeleton Code:
Public String Delerubbishad () {
int deleadcount = 0;
RUBBISHADTP = CONFIGDAO.RUBBISHADTP ();Collection of ad images in the database
map<object,object> shujuku= new hashmap<object,object> ();
File Adfile = new file ("C://program Files//apache software foundation//tomcat 6.0//webapps//plpwmanagers// Yesilovepjustdoit2014//adimg ");
String adarray[];
Adarray=adfile.list ();An array of ad images on the server, since the IE storage mechanism, the resulting files from the server are included with a thumbs.db thumbnail file. No need to deal with this
Put a database ad image in map
for (Object SHUJUKUAD:RUBBISHADTP) {
Shujuku.put (Shujukuad, Shujukuad);
}
list<object> diffenttp= new arraylist<object> ();A picture used to store differences
The loop infers the pictures in the server which are not in the database
for (String Fuwuqi:adarray) {
if (Shujuku.containskey (Fuwuqi) ==false) {
Diffenttp.add (Fuwuqi);
}
}
To cycle through the deletion of the difference picture
for (int i =0;i<diffenttp.size () -1;i++) {//thumbs.db file does not need to be processed
Find the diff picture on the server
File filead= new file (Servletactioncontext.getservletcontext (). Getrealpath ("yesilovepjustdoit2014/adimg") + "/" + Diffenttp.get (i));
Filead.delete ();
deleadcount++; Record how many diff images were deleted
}
Rubbadmap.put ("Lajiadcount", Diffenttp.size ()-1);
Rubbadmap.put ("Deleadcounts", Deleadcount);
return "DELERUBBISHADSUC"; The returned result is the number of garbage images. Image number of the sheet to delete
}
Set difference set Hash table compare the photos on the database and on the server screen, delete the pictures on the server trash