logo image

Filter all files with a particular extension in Java

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

1 Answer

2 years ago by

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
2 years ago by Megamind