Java recursive method to find a directory containing a string

Source: Internet
Author: User

Recently, when installing mysql5.6, some configuration items need to be configured manually because they are free of installation versions. But when configuring an item (for example: max_allowed_packet=xxxxx), I do not know where the max_allowed_packet string is, and I haven't found it for half a day. So I wondered if I could use the recursive implementation of Java. Buy on behalf of the following:

 Packagetest;ImportJava.io.BufferedReader;ImportJava.io.File;Importjava.io.FileNotFoundException;ImportJava.io.FileReader;Importjava.io.IOException;Importjava.util.ArrayList;Importjava.util.List; Public classwordfind{ Public Static voidMain (string[] args) {File F=NewFile ("d:\\mysql5.6"); List List= Getcontainsswordfile (NewArrayList (), F,"Max_allowed_packet", "CNF");  for(inti = 0; I < list.size (); i++) {File F_result=(File) list.get (i);        System.out.println (F_result.getabsolutepath ()); }    }     Public Staticlist getcontainsswordfile (List list, File des_file,FinalString Contains_word,FinalString Serch_file) {         for(File pathname:des_file.listFiles ()) {if(Pathname.isfile ()) {//if the method of the query is to contain serch_file if there is, continue to determine whether the text is included Contains_word                if(Pathname.getname (). Contains (Serch_file)) {Try{FileReader fr=NewFileReader (pathname); BufferedReader BR=NewBufferedReader (FR); String Str= "";//                         while(NULL! = (str =Br.readline ())) {                            if(Str.contains (Contains_word)) {//Add inList.add (pathname); }                        }                    }                    Catch(FileNotFoundException e) {e.printstacktrace (); }                    Catch(IOException e) {e.printstacktrace (); }                }            }            Else{List=getcontainsswordfile (list, pathname, Contains_word, serch_file); }        }        returnlist; }}

This method can also be improved to make it possible to replace all contained strings in a directory.

Java recursive method to find a directory containing a string

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.