标签:return tabs code system sql absolute catch contains ++
最近在安装mysql5.6的时候,因为是免安装版的所以有些配置项需要手动配置。但是配置某一项的时候(例如:max_allowed_packet=xxxxx),不知道max_allowed_packet这个字符串在哪里,找了半天没找到。于是我就想了是否可以用java的递归实现。代买如下:
package test; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class WordFind { public static void main(String[] args) { File f = new File("D:\\mysql5.6"); List list = getContainssWordFile(new ArrayList(), f, "max_allowed_packet", "cnf"); for (int i = 0; i < list.size(); i++) { File f_result = (File) list.get(i); System.out.println(f_result.getAbsolutePath()); } } public static List getContainssWordFile(List list, File des_file, final String contains_word, final String serch_file) { for (File pathname : des_file.listFiles()) { if (pathname.isFile()) { // 如果查询的方法是包含serch_file 如果有,继续判断是否包含文字contains_word if (pathname.getName().contains(serch_file)) { try { FileReader fr = new FileReader(pathname); BufferedReader br = new BufferedReader(fr); String str = "";// while (null != (str = br.readLine())) { if (str.contains(contains_word)) { // 添加进去 list.add(pathname); } } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } else { list = getContainssWordFile(list, pathname, contains_word, serch_file); } } return list; } }
这个方法也可以改进改进就能达到替换某目录下所有包含某字符串。
标签:return tabs code system sql absolute catch contains ++
原文地址:http://www.cnblogs.com/loveMoon/p/6182926.html