|
public static boolean findInFiles(String filename, String regex) throws IOException {
final String filtername = ".*" + filename + ".*";
File dir = new File("e:" + File.separator + "dir" + File.separator); //files directory
//get the file-list of the relative files for searching
File [] files = dir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
if (name.matches(filtername)) {
return true;
}
return false;
}
});
for (int i = 0;i < verbsFiles.length; i ++ ) {
//read one file of the files for searching
BufferedReader bufreader = new BufferedReader(new FileReader(files));
String line_str = "";
while(bufreader.ready()) //read each line
{
line_str = bufreader.readLine();
if(line_str.isEmpty()) {
continue;
} else if(line_str.indexOf(',') == -1) {
line_str = line_str.replaceAll("\\t.*\\t", ":"); //replace "\t*\t" by ":"
if(line_str.compareTo(regex) == 0) {
return true; //same, true
}
}else if(line_str.indexOf(',') != -1) {
if(extendSearch(line_str, regex)) {
return true;
}
}
}
bufreader.close();
}
return false;
} |
|