Edit
You can fetch the known directory files
and recursively list all the File[]
objects.
It would be easier if you user org.apache.commons.io.FileUtils.listFiles(File directory, String[] extensions, boolean recursive);
I've created a helper function like below to wrap the logic of String.format
and classpath:
public static File getResourceAsFile(String relativeFilePath) throws FileNotFoundException {
return ResourceUtils.getFile(String.format("classpath:%s",relativeFilePath));
}
And to use it,
String relativeFilePath ="files";
File file =getResourceAsFile(relativeFilePath);
Collection<File> files=FileUtils.listFiles(file,null,true); //
And if you want to read all the xml
files, then pass second parameter as
Collection<File> files=FileUtils.listFiles(file,new String[]{"xml"},true);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…