Set difference set Hash table compare the photos on the database and on the server screen, delete the pictures on the server trash

Source: Internet
Author: User
Tags diff

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.