import java.nio.file.*;
import java.util.*;
public class PathMatcherExample {
public static void main(String[] args) {
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:*.txt");
List<String> filePaths = Arrays.asList("file1.txt", "file2.xml", "file3.txt", "file4.csv");
for (String filePath : filePaths) {
Path path = Paths.get(filePath);
if (matcher.matches(path)) {
System.out.println("Matched: " + filePath);
}
}
}
}
Matched: file1.txt
Matched: file3.txt