I'm doing a recursive directory tour and I want to export the directories and files found to an excel file. This is my code
package packages;
import java.io.File;
import java.io.FileOutputStream;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class hh {
public void leer(String inicio, String altura) {
File ar = new File(inicio);
String[] dir = ar.list();
XSSFWorkbook book = new XSSFWorkbook();
XSSFSheet sheet = book.createSheet();
for (int f = 0; f < dir.length; f++) {
File ar2 = new File(inicio + dir[f]);
String sss = "Directorio: " + dir[f];
XSSFRow row = sheet.createRow(f);
if (ar2.isFile()) {
//System.out.println(altura + dir[f]);
}
if (ar2.isDirectory()) {
System.out.println(altura + "Directorio:" + dir[f]);
for (int j = 0; j < dir.length; j++) {
XSSFCell cell = row.createCell(j);
cell.setCellValue(sss);
}
leer(inicio + dir[f] + "\", altura + " ");
}
}
try {
FileOutputStream out = new FileOutputStream(new File("C:\Users\Desktop\jdjdj.xlsx"));
book.write(out);
System.out.println("Excel written successfully..");
} catch (Exception e) {
}
}
public static void main(String[] arguments) {
hh rec = new hh();
rec.leer("C:\Users\Desktop\internacionales\", "");
}
}
When the .xlsx file is generated, it only shows me the main folders, that is, the first folders that it finds in the path that you specify. I want to print all the subfolders in an excel file