I\'d like to check if a Path (introduced in Java 7) ends with a certain extension. I tried the endsWith() method like so:
endsWith()
Path path = Paths.get
Java NIO's PathMatcher provides FileSystem.getPathMatcher(String syntaxAndPattern):
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:*.java"); Path filename = ...; if (matcher.matches(filename)) { System.out.println(filename); }
See the Finding Files tutorial for details.