I have the following recursive method, which simply adds all the children to the given folder in the list:
private List<TemplateFile> readTemplateFiles(String nextTemplateDir, String rootTemplateDir) throws FileNotFoundException { List<TemplateFile> templateFiles = new ArrayList<>(); for (File file : new File(nextTemplateDir).listFiles()) { if (!file.isDirectory() && !file.getName().startsWith(".")) { templateFiles.add(TemplateFile.create(file, rootTemplateDir)); } else if (file.isDirectory()) { templateFiles.addAll(readTemplateFiles(file.getAbsolutePath(), rootTemplateDir)); } } return templateFiles; }
How can I reorganize this method using the new Java 8 Stream API?
source share