The set difference set hash table compares images in the database with those on the server, and deletes junk images on the server.

Source: Internet
Author: User

Code in the SSH framework:


Public String deleRubbishAd (){
Int deleADcount = 0;
RubbishADtp = configDao. rubbishADtp (); // ad image set 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 (); // The ad Image array on the server. Due to the IE storage mechanism, all files obtained from the server contain a Thumbs. the thumbnail file of the db, which does not need to be processed here
// Put the advertisement image of the database into the map
For (Object shujukuad: rubbishADtp ){
Shujuku. put (shujukuad, shujukuad );
}
List <Object> diffentTp = new ArrayList <Object> (); // stores different images.
// Cyclically determine which images on the server are not in the database
For (String fuwuqi: adarray ){
If (shujuku. containsKey (fuwuqi) = false ){
DiffentTp. add (fuwuqi );
}
}
// Cyclically Delete different images
For (int I = 0; I <diffentTp. size ()-1; I ++) {// Thumbs. db file does not need to be processed
// Find the difference image on the server
File filead = new File (ServletActionContext. getServletContext (). getRealPath ("yesilovepjustdoit2014/AdImg") + "/" + diffentTp. get (I ));
Filead. delete ();
DeleADcount ++; // records the number of different images deleted
}
RubbADmap. put ("lajiadcount", diffentTp. size ()-1 );
RubbADmap. put ("deleadcounts", deleADcount );
Return "delerubbishADsuc"; // The number of junk images is returned, and the number of images is deleted.
}


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.