Java reads the files with the specified suffix under the specified directory
1. POM import dependencies
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
2. Example
Take the .java file as an example, the specified directory is directory, and the third parameter of listFiles indicates whether to recurse, and recursion means reading subdirectories
import org.apache.commons.io.FileUtils;
import java.io.File;
...
File rootDir = new File("D://test");
Collection<File> files = FileUtils.listFiles(rootDir, new String[]{"java"}, true);
//标识读取D://test目录下面所有.java的文件