So I have this program that reads an excel file and goes through the Column C cells and creates a new Directory for each of them, inside those directories create a text files with the content of column B inside it.
Im using netbeans GUI builder so I want to add a progress bar and link it to a function so when the function is executed the progress bar should run with it and when it finish the progress bar should be 100%
so this is my function can anyone help me?
public void CreateDir(String path) throws IOException {
try {
FileInputStream fis = new FileInputStream(path);
XSSFWorkbook wb = new XSSFWorkbook(fis);
XSSFSheet sheet = wb.getSheetAt(0);
for (int i = 1; i < sheet.getPhysicalNumberOfRows(); i++) {
XSSFRow row = sheet.getRow(i);
XSSFCell cell = row.getCell(2);
//cell.setCellType(Cell.CELL_TYPE_STRING);
try {
if (cell != null) {
File dir = new File(getWorkSpacePath() + "\\" + cell);
// if the directory does not exist, create it
//System.out.println(Files.list(Paths.get(getWorkSpacePath()+dir.getName())).count());
if (!dir.exists()) {
try {
dir.mkdir();
} catch (SecurityException se) {
se.printStackTrace();
}
}
for (int j = i; j < sheet.getPhysicalNumberOfRows(); j++) {
File file = new File(getWorkSpacePath() + "\\" + dir.getName() + "\\" + sheet.getRow(i).getCell(0) + ".txt");
try {
PrintWriter writer = new PrintWriter(file);
writer.println(sheet.getRow(i).getCell(1).toString());
writer.close();
//System.out.println(Files.list(Paths.get(getWorkSpacePath() + "\\" + dir.getName())).count());
//countFilesInDirectory(getWorkSpaceFile());
} catch (IOException e) {
System.out.println("Error, " + e);
}