Description
My goal is to store all file paths in a file. To do that I built a recursive method which browse a specific folder. However, the result is still empty ...
Code
public void main(String[] args) {
String files = browseFolder("", new File("blablalbla/.../toto"));
FileWriter writer = new FileWriter(new File("result/"));
writer.write(files);
writer.close();
}
private static String browseFolder(String result, File folder) {
for (final File fileEntry : folder.listFiles()) {
if (fileEntry.isDirectory()) {
browseFolder(result, fileEntry);
}
else {
System.out.println(fileEntry.getPath());
result += fileEntry.getPath() + "\n";
}
}
return result;
}
All files are displayed in the console thanks to the sysout
. However, my result file is empty.
Any idea ? Thank you.