Ideas: first determine whether a file, if the file you need to determine whether to change the file name contains the string "txt", contains the output. If it is a folder, then first need to determine whether the file name contains the ".txt" (because the file name may contain txt), and then use the recursive method to traverse subfolders.
Code: Method
public static void SearchAtString(File file,String str) { if(file.isFile()) { if((file.getName().indexOf(str))!=-1) { System.out.println(file.getAbsolutePath()); } }else if(file.isDirectory()) { File[] files = file.listFiles(); for(File f:files) { if(f.getName().indexOf(str)!=-1) { System.out.println(f.getAbsolutePath()); } SearchAtString(f,str); } } }
operation result: