Tells you if a file matches your pattern
FileSystem fileSystem = FileSystems.getDefault();
PathMatcher pathMatcher = fileSystem.getPathMatcher("glob:**/testFile.?");
Path path = Paths.get("D:/cp/testFile.t");
System.out.println(pathMatcher.matches(path));
The "glob:" says that we are glob. You can also regex
* It matches zero , one or more than one characters.
While matching, it will not cross directories boundaries.
** It does the same as * but it crosses the directory boundaries.
? It matches only one character for the given name.
\ It helps to avoid characters to be interpreted as special characters.
[] In a set of characters, only single character is matched.
If (-) hyphen is used then, it matches a range of characters.
Example: [efg] matches "e","f" or "g" . [a-d] matches a range from a to d.
{} It helps to matches the group of sub patterns.
In case of "regex", pattern is regular expression defined by java.util.regex.Pattern.
Read java.util.regex.Pattern to get "regex" more.
If you want to find a file that matches the pattern consider using FileVistor
and implementing its methods to visit each file in a directory