import com.google.common.base.Charsets;
import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class FileContains {
static void getParams(String classPath, String methodName) throws IOException {
//判断当前文件出现次数
int num = 0;
File file = new File(classPath);//定义文件
String params = "";
//每行作为一个字符串,存为列表元素
List<String> strings = Files.readLines(file, Charsets.UTF_8);
for (String string : strings) {
//判断是否包含方法名称,即指定字符串
if (string.contains(methodName)) {
//包含不为0
num++;
}
}
if(num==0){
//这里输出不包含的文件路径
System.out.println(classPath);
}
}
public static void main(String[] args) throws IOException {
//遍历某个文件夹下的所有以.vue结尾的文件
//文件夹
String folder = "E:\\VsCodeWorkSpace\\prod\\manage\\src\\code";
//指定类型的文件
String suffix = ".vue";
//包含某个字符串
String word = "@/utils/validate.js";
traverseFolder(folder,suffix,word);
}
public static void traverseFolder(String path,String suffix,String word) throws IOException {
File file = new File(path);
if (file.exists()) {
File[] files = file.listFiles();
if (null == files || files.length == 0) {
System.out.println("文件夹是空的!");
return;
} else {
for (File file2 : files) {
if (file2.isDirectory()) {
traverseFolder(file2.getAbsolutePath(),suffix,word);
} else {
if(file2.getAbsolutePath().contains(suffix)){
getParams(file2.getAbsolutePath(),word);
}
}
}
}
} else {
System.out.println("文件不存在!");
}
}
}
03-19
1万+
