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