Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.File;
import java.io.FilenameFilter;

public class Main {
    public static void main(String[] args) {
        File f = new File("c:/test");
        FilenameFilter fileNameFilter = new FilenameFilter() {
            @Override
            public boolean accept(File dir, String name) {
                if (name.lastIndexOf('.') > 0) {
                    int lastIndex = name.lastIndexOf('.');
                    String str = name.substring(lastIndex);
                    if (str.equals(".txt")) {
                        return true;
                    }
                }
                return false;
            }
        };
        File[] paths = f.listFiles(fileNameFilter);
        for (File path : paths) {
            System.out.println(path);
        }
    }
}