Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import java.io.File;

import javax.swing.filechooser.FileFilter;

public class Main {
    /**
     * Creates a FileFilter for a specified description
     * and an array of allowed extensions. <br />
     * 
     * @param extensions the allowed extensions without a dot
     * @param description the displayed description
     * @return the created FileFilter
     */
    public static FileFilter createFilter(final String[] extensions, final String description) {
        return new FileFilter() {

            @Override
            public boolean accept(File file) {
                if (file.isDirectory()) {
                    return true;
                }
                String name = file.getName().toLowerCase();
                for (String e : extensions) {
                    if (name.endsWith("." + e.toLowerCase())) {
                        return true;
                    }
                }
                return false;
            }

            @Override
            public String getDescription() {
                return description;
            }
        };
    }
}