Skip to content

io microsphere io filter FileExtensionFilter

github-actions[bot] edited this page Mar 21, 2026 · 1 revision

FileExtensionFilter

Type: Class | Module: microsphere-java-core | Package: io.microsphere.io.filter | Since: 1.0.0

Source: microsphere-java-core/src/main/java/io/microsphere/io/filter/FileExtensionFilter.java

Overview

A filter that matches files based on their extensions.

This class implements the IOFileFilter interface and provides functionality to filter files by checking if their extension matches a specified extension. The comparison is case-insensitive on Windows systems, while it's case-sensitive on other operating systems.

Example Usage

`// Create a filter for ".txt" files
IOFileFilter txtFilter = FileExtensionFilter.of(".txt");

// Use the filter to accept only ".txt" files
File dir = new File("/path/to/directory");
File[] txtFiles = dir.listFiles((FileFilter) txtFilter);
`

The above example creates a filter that accepts only files ending with the ".txt" extension. It then uses this filter to list all matching files in the specified directory.

Declaration

public class FileExtensionFilter implements IOFileFilter

Author: Mercy

Version Information

  • Introduced in: 1.0.0
  • Current Project Version: 0.1.10-SNAPSHOT

Version Compatibility

This component is tested and compatible with the following Java versions:

Java Version Status
Java 8 ✅ Compatible
Java 11 ✅ Compatible
Java 17 ✅ Compatible
Java 21 ✅ Compatible
Java 25 ✅ Compatible

Examples

// Create a filter for ".txt" files
IOFileFilter txtFilter = FileExtensionFilter.of(".txt");

// Use the filter to accept only ".txt" files
File dir = new File("/path/to/directory");
File[] txtFiles = dir.listFiles((FileFilter) txtFilter);

Usage

Maven Dependency

Add the following dependency to your pom.xml:

<dependency>
    <groupId>io.github.microsphere-projects</groupId>
    <artifactId>microsphere-java-core</artifactId>
    <version>${microsphere-java.version}</version>
</dependency>

Tip: Use the BOM (microsphere-java-dependencies) for consistent version management. See the Getting Started guide.

Import

import io.microsphere.io.filter.FileExtensionFilter;

API Reference

Public Methods

Method Description
accept
of Creates an instance of FileExtensionFilter by the given file extension

Method Details

of

public static FileExtensionFilter of(String extension)

Creates an instance of FileExtensionFilter by the given file extension

See Also

  • IOFileFilter
  • FileUtils#getFileExtension(String)

This documentation was auto-generated from the source code of microsphere-java.

Home

java-annotations

java-core

jdk-tools

lang-model

annotation-processor

java-test

Clone this wiki locally