Filter all files with a particular extension in Java

Views: 196 Ask New Question

How can i filter files with particular extension in Java, let say i want to filter all .json files from a folder.

On By

1 Answer

Following code filters all json files from the flder /path/to/folder

Arrays.asList(Paths.get("/path/to/folder").toFile().listFiles(file -> !file.isHidden() &&  file.isFile() && (file.getName().endsWith(".json")))).forEach(file -> {
    // deal with the file
On By

Answer This Question