Pathの拡張子をチェックしたい場合、PathMatcherクラスのmatchesメソッドを利用します。
例) Pathの拡張子がcsvかどうかをチェックする
Path path = Path.of("Path/To/Target.csv");
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:**.csv");
if (matcher.matches(path)) {
System.out.println("This file is csv.");
} else {
System.out.println("This file is not csv.");
}
環境情報
C:\>javac -version
javac 21-beta
C:\>java -version
openjdk version "21-beta" 2023-09-19
OpenJDK Runtime Environment Temurin-21+35-202309042131 (build 21-beta+35-ea)
OpenJDK 64-Bit Server VM Temurin-21+35-202309042131 (build 21-beta+35-ea, mixed mode, sharing)