Replicating Directory.GetFiles(String, String) in Java
<h2>Overview</h2>

<p>I'm in the process of porting a simple utility app over from C# into Java and as part of this I'm writing some helper methods for items where I prefer C#'s semantics. Once such case is <a href="http://msdn.microsoft.com/en-us/library/3hwtke0f.aspx" rel="nofollow"><code>Directory.GetFiles</code></a>.</p>

<h2>Current Code</h2>

<pre><code>import java.io.File;
import java.io.FilenameFilter;

public class Directory {
    public static String[] GetFiles(String path) {        
        File directory = new File(path);

         return directory.list(new FilenameFilter() {
            @Override
            public boolean accept(File dir, String filename) {
                return new File(dir, filename).isFile();
            }
        });
     }
}
</code></pre>

<h2>Question</h2>

<p>Whilst the above all seems fine, and replicates one of the GetFiles overloads, I'm stuck on how best to write a method that replicates the functionality of C#'s <a href="http://msdn.microsoft.com/en-us/library/wz42302f.aspx" rel="nofollow"><code>Directory.GetFiles(String, String)</code></a>.</p>

<p>This method should take a <code>path</code> string, as well as a <code>searchPattern</code>, which is used to return only files matching that particular pattern.</p>

<p>For example, each of the following should work:</p>

<pre><code>// Used to get all JavaScript files
Directory.GetFiles("~/Documents/", "*.js");

// Get all CSS files in the styles sub-folder.
Directory.GetFiles("~/Documents/", "styles/*.css"); 
</code></pre>
