Multi-threaded synchronization to find files that contain specific content

Source: Internet
Author: User

 PackageCom.zdst.scs.business.hystric.checkflow;ImportJava.io.*; Public classFiletest { Public Static voidMain (string[] args) {FindFile ("E:\\dubbo"); }         Public Static voidfindfile (String path) {//get a list of files under the directoryfile[] FileList =NewFile (path). Listfiles (); //The directory is not empty            if(Filelist.length > 0){                //iterate through the file array, if it is a directory, call this method recursively, if it is a file, determine whether the. Java end, and then call the Read file method to determine                 for(File file:filelist) {if(File.isdirectory ()) {FindFile (File.getabsolutepath ()); }Else{                        if(File.getname (). EndsWith (". Java") {threadtest thread=NewThreadTest (file, "log"); Newthread (thread). Start (); }                    }                }            }        }} classThreadTestImplementsrunnable{Privatefile file; PrivateString Key;  Publicthreadtest (File file,string key) { This. File =file;  This. Key =key; } @Override Public voidrun () {BufferedReader bufferedreader; Try {            //gets the read stream of the fileBufferedReader =NewBufferedReader (Newfilereader (file)); StringBuffer SB=NewStringBuffer (); String Line= ""; //read the file and append it to the StringBuffer             while(line = Bufferedreader.readline ())! =NULL) {sb.append (line); }            //matches whether a specific keyword exists            if(Sb.tostring (). Contains (key)) {System.out.println (File.getname ()); }        } Catch(FileNotFoundException e) {e.printstacktrace (); }Catch(IOException e) {e.printstacktrace (); }            }    }

Multi-threaded synchronization to find files that contain specific content

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.