Java NIO's PathMatcher provides FileSystem.getPathMatcher(String syntaxAndPattern):
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:*.java");
Path filename = ...;
if (matcher.matches(filename.getFileName())) {
System.out.println(filename);
}
.getFileName() is required when your path contains more than one component.
See the Finding Files tutorial for details.
Answer from fan on Stack OverflowJava NIO's PathMatcher provides FileSystem.getPathMatcher(String syntaxAndPattern):
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:*.java");
Path filename = ...;
if (matcher.matches(filename.getFileName())) {
System.out.println(filename);
}
.getFileName() is required when your path contains more than one component.
See the Finding Files tutorial for details.
The Path class does not have a notion of "extension", probably because the file system itself does not have it. Which is why you need to check its String representation and see if it ends with the four five character string .java. Note that you need a different comparison than simple endsWith if you want to cover mixed case, such as ".JAVA" and ".Java":
path.toString().toLowerCase().endsWith(".java");
What you want to do is append a / character to a String. A Path object is not a String, you cannot append a / character to it. And you don't have to. It's not the last character that determines whether the Path refers to a folder or a file.
You can write
Paths.get( "/Test/Location", Group, database );
to get a well-formed Path. There's no need for the '/' at the end.