I was doing a program that searches a directory recursively and matches a String "Claims" with the file names.
If the files are found with name starting from Claims they shall be shown in the output.
I am posting my code below.
import java.io.File;
public class FileSearchRecursively {
public static void main(String[] args){
FileSearchRecursively f=new FileSearchRecursively();
f.listFile("D:/Abhishek/src", "Claims" );
}
public void listFile(String pathname,String searchKey) {
File f = new File(pathname);
File[] listfiles = f.listFiles();
for (int i = 0; i < listfiles.length; i++) {
if (listfiles[i].isDirectory()) {
File[] internalFile = listfiles[i].listFiles();
for (int j = 0; j < internalFile.length; j++) {
String val=internalFile[j].getAbsolutePath();
if (internalFile[j].isDirectory()) {
String name = internalFile[j].getAbsolutePath();
listFile(name,searchKey);
}else
{
if(val.equals(searchKey));
}
}
}
else {
System.out.println(listfiles[i]);
}
}
}
}