0

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);
                        }
Qubayl
  • 77
  • 1
  • 8
  • Don't you know there exists tutorial threads for various subject like: https://docs.oracle.com/javase/tutorial/uiswing/components/progress.html – Jean-Baptiste Yunès Apr 22 '17 at 05:42
  • Possible duplicate [java swingworker thread to update main Gui](http://stackoverflow.com/questions/16937997/java-swingworker-thread-to-update-main-gui/16938228#16938228), [JProgressBar isn't progressing](http://stackoverflow.com/questions/12020949/jprogressbar-isnt-progressing/12021971#12021971), [JProgressBar won't update](http://stackoverflow.com/questions/13094666/jprogressbar-wont-update/13095992#13095992) – MadProgrammer Apr 22 '17 at 06:00
  • no I didnt but thank I'll chek it now – Qubayl Apr 22 '17 at 06:15

0 Answers0