Collection Difference set Hash table compare the pictures in the database and the pictures on the server, delete the junk pictures on the server

Source: Internet
Author: User
Tags diff

Under SSH Framework 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, as the IE storage mechanism, the resulting files from the server contain a thumbs.db thumbnail file, where there is no need to process
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
Cycle through the images 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"; Returns the number of trash pictures, deleting the number of pictures
}


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.