Find files from a directory in Java


In Java, it’s not so hard to find the specific files you need from a directory. You can easily do that with the code below:

final String directory = \\path\to\directory\;
final File file = new File(directory);
File[] matchingFiles = file.listFiles(new FilenameFilter() {
    public boolean accept(File dir, String name) {
        return !name.startsWith("myfile") && !name.endsWith("txt");

The first file =


The second file =


and so on

Add comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Tag Cloud


%d bloggers like this: