Clear unused images, JS, CSS code in Eclipse projects

Source: Internet
Author: User

ImportJava.io.BufferedReader;ImportJava.io.File;ImportJava.io.FileReader;Importjava.io.IOException;ImportJava.nio.file.Files;Importjava.nio.file.Paths;Importjava.util.ArrayList;Importjava.util.List; Public classClearfile {StaticString folder = "E:\\newserver\\wechat\\joint_care\\source"; List<FilePojo> filelist =NewArraylist<filepojo>(); List<FilePojo> ContentList =NewArraylist<filepojo>();  Public Static voidMain (string[] args)throwsIOException {clearfile Clear=NewClearfile ();            Clear.clear (folder); }         Public voidClear (String folder)throwsioexception{getallfilepaths (NewFile (folder)); Getcontentfiles (NewFile (folder));  for(Filepojo file:contentlist) {search (File.getpath ()); } System.out.println ("****************************************** deleted the following files ************************************");  for(Filepojo file:filelist) {if(!File.isfind ())                {System.out.println (File.getpath ()); NewFile (File.getpath ()). Delete (); }        }    }         Private voidgetallfilepaths (File filePath) {file[] files=Filepath.listfiles ();  for(File file:files) {if(File.isdirectory ()) {getallfilepaths (file); }Else{String filename=File.getname (); if(Filename.contains (". jpg")                         || Filename.contains (". png")                        || Filename.contains (". gif")                        || Filename.contains (". js"))                        || Filename.contains (". css") {Filepojo Pojo=NewFilepojo ();                    Pojo.setname (File.getname ());                                    Pojo.setpath (File.getpath ());                Filelist.add (Pojo); }            }        }    }        Private voidgetcontentfiles (File filePath) {file[] files=Filepath.listfiles ();  for(File file:files) {if(File.isdirectory ()) {getcontentfiles (file); }Else{String filename=File.getname (); if(Filename.contains (". html")                         || Filename.contains (". FTL"))                         || Filename.contains (". css")                        || Filename.contains (". js"))                        || Filename.contains (". Java") {Filepojo Pojo=NewFilepojo ();                    Pojo.setname (File.getname ());                                    Pojo.setpath (File.getpath ());                Contentlist.add (Pojo); }            }        }    }         Public voidSearch (String filename)throwsIOException {bufferedreader br=NewBufferedReader (Newfilereader (filename));  for(String line; (line = Br.readline ())! =NULL; ) {                             for(Filepojo file:filelist) {if(Line.contains (File.getname ())) {File.setfind (true);    }}} br.close (); }         Private classfilepojo{PrivateString name; PrivateString Path; Private Booleanfind;  PublicString GetName () {returnname; }         Public voidsetName (String name) { This. Name =name; }         PublicString GetPath () {returnpath; }         Public voidSetPath (String path) { This. Path =path; }         Public BooleanIsfind () {returnfind; }         Public voidSetfind (Booleanfind) {             This. Find =find; }    }}

There is a small problem: If the file name is 01.jpg, Xx01.jpg is referenced in the code, then 01.jpg is considered a required file.

Clear unused images, JS, CSS code in Eclipse projects

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.