Class RegexFileFilter

  • All Implemented Interfaces:
    java.io.FileFilter

    public class RegexFileFilter
    extends java.lang.Object
    implements java.io.FileFilter
    This class provides a simple regex-based file filter for use with File.listFiles(java.io.FileFilter). The regex pattern is provided to the constructor and is used to check files when retrieving directory listings. Note that only the file's name is tested; the path is not considered in the check.
    See Also:
    File.listFiles(java.io.FileFilter), Pattern
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.regex.Matcher matcher
      This matcher is initialized from the regex pattern, and is used to do the actual filename testing.
      private java.util.regex.Pattern pattern
      The regex pattern used for matching against filenames.
    • Constructor Summary

      Constructors 
      Constructor Description
      RegexFileFilter​(java.lang.String regex)
      Initialize a new regex file filter with the specified regex pattern.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean accept​(java.io.File file)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • pattern

        private java.util.regex.Pattern pattern
        The regex pattern used for matching against filenames.
      • matcher

        private java.util.regex.Matcher matcher
        This matcher is initialized from the regex pattern, and is used to do the actual filename testing.
    • Constructor Detail

      • RegexFileFilter

        public RegexFileFilter​(java.lang.String regex)
        Initialize a new regex file filter with the specified regex pattern.
        Parameters:
        regex - The regex pattern to check filenames against.
    • Method Detail

      • accept

        public boolean accept​(java.io.File file)
        Specified by:
        accept in interface java.io.FileFilter