java - Read files in a Task -


i'm beginner in java , javafx. have problem, want count pdfs in folders , want show process in progressbar.

i know quantity of pdf's , must check if there.

the method read folder's is:

private void dir(file fileroot) {      file[] files = fileroot.listfiles();      for(file file : files) {          if(file.isdirectory()){              dir(file);          }              else{              string dateiname = file.getname();              if(dateiname.endswith(".pdf")){                  ++countpdf;                  system.out.println(countpdf);                            }          }      } 

the method update progressbar is:

private task<boolean> createworker() {         return new task<boolean>() {         @override         protected boolean call() throws exception {                      updatemessage(countpdf + "");                     updateprogress(countpdf, number);              }             return true;         };     } 

how can combine there in controller?

public class controller {     @fxml     private button startbutton;     @fxml     private progressbar myprozessbar;     @fxml     private label label;      private int countpdf;     private file directory;      @fxml     private void actionstart(actionevent event) {           string path = "c:\\root\\";         directory = new file(path);              myprozessbar.progressproperty().unbind();                 myprozessbar.progressproperty().bind(task.progressproperty());         label.textproperty().bind(task.messageproperty());     }      @fxml     void initialize() {      } 

i'm trying several days solve , have no more idea.

please me.

you can this:

private path directory;  .....         private task<observablelist<integer>> createworker() {      return new task<observablelist<integer>>() {         @override         protected observablelist<integer> call() throws exception {             stack<path> stack = new stack();             stack.push(directory);             int = 0;             while (!stack.empty()) {                 if (iscancelled()) {                     break;                 }                 path root = stack.pop();                 try (directorystream<path> stream = files.newdirectorystream(root);) {                     (path path : stream) {                         if (files.isdirectory(path)) {                             stack.push(path);                         } else {                              if (path.tostring().endswith(".pdf")) {                                 i++;                                 results.add(i);                                 updateprogress(i, 100);                                 updatevalue(results);                                 thread.sleep(5);                             }                         }                     }                 } catch (ioexception ex) {                     system.out.println(ex.getmessage());                 }              }             return results;         }      };  } 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -