File path returns 'null' for a given location and filename
<p>Can somebody please tell me where I am wrong in the code.I am trying to search for a particular file named <code>filename</code> in a directory path and trying to return the <code>filepath</code> but it is always returning <code>null</code>.</p>

<p>Here is the code I'm using:</p>

<pre><code>public String walk( String path, String filename ) {
String filePath = null;
    File root = new File( path );
    File[] list = root.listFiles();

    for ( File f : list ) {
        if ( f.isDirectory() ) {
            walk( f.getAbsolutePath(),filename );
           }
        else if (f.getName().equalsIgnoreCase(filename)){
            System.out.println( "File:" +f.getAbsolutePath() );
            filePath= f.getAbsolutePath();
           if(filePath.endsWith(memberPath)){
               System.out.println( "Found: Should exit");
               break;
           }
        }
     }
    System.out.println( "OUT of for:"  );
    return filePath;
}
</code></pre>

<p>it prints<br>
     OUT of for: </p>

<pre><code> OUT of for:    

 File:d:\IM\EclipseWorkspaces\runtime-EclipseApplication\SIT\So\mmm\aaa\xxx.c

Should exit

OUT of for:

OUT of for:
</code></pre>

<p>I dont understand why it still goes back to the loop</p>

<p>EDIT: UPDATE:</p>

<p>I have found another way. please correct if there is something wrong  :declare filePath as a static variable</p>

<pre><code>    public static void walk( String path, String filename ) {

    File root = new File( path );
    File[] list = root.listFiles();

    for ( File f : list ) {
       if ( f.isDirectory() ) {
            walk( f.getAbsolutePath(),filename );
           }
        else if (f.getName().equalsIgnoreCase(filename) &amp;&amp; f.getAbsolutePath().endsWith(memberPath)){
             System.out.println( "Should exit");
             filePath = f.getAbsolutePath();
             break;
     }
       }

}
</code></pre>
