在Java中的多个文件中搜索匹配字符串

在Java中的多个文件中搜索匹配字符串,java,file,Java,File,我试图在java中搜索多个文本文件,寻找匹配的随机字符串(由用户提供)。我给自己弄了一个循环,循环项目中当前目录中的文件名,但我不知道如何打开这些文件并检查它们是否匹配。下面是我为循环文件名而编写的代码 String path = "."; //current directory java.io.File folder = new java.io.File( path ); java.io.File[] fileList = folder.listFiles(); f

我试图在java中搜索多个文本文件,寻找匹配的随机字符串(由用户提供)。我给自己弄了一个循环,循环项目中当前目录中的文件名,但我不知道如何打开这些文件并检查它们是否匹配。下面是我为循环文件名而编写的代码

String path = ".";  //current directory 
    java.io.File folder = new java.io.File( path );
    java.io.File[] fileList = folder.listFiles();
    for( int i = 0; i < fileList.length; i++ ) {
    // I should add code for searching int the files probably here 
    }
但它只能处理一个文件,或者在我看来是这样的


你能帮我推一下吗?:)

文件列表[i]
替换
文件名
,您应该已经上路了


顺便说一下,您必须记住在循环的每次迭代结束时通过调用
scanner.close()
关闭扫描仪。查看更多信息

您有(1)一个文件列表和(2)一个接受单个文件名并扫描该文件的函数。。您认为还需要什么?除了处理文件之外,在本例中还需要。
final Scanner scanner = new Scanner(FileName); 
    while (scanner.hasNextLine())  {
       final String lineFromFile = scanner.nextLine(); 
       if(lineFromFile.contains("Address"))  { 
           // a match!
           System.out.println("I found " + CurrClient.getClientName() 
                         + " in file " +FileName+"txt");
           break;
       }
    }