0

I am processing a large number of files, say 1000 files using a java program. Processing each file takes significant amount of time. Problem is : when I process a file, due to some unknown problem (may be antivirus or any other problem) the input file is not able to be accessed by java program, so I get "Access is denied" and ultimately "java.io.FileNotFoundException".

One of the possible solution is to whenever I get the exception I process the file again calling the function, but calling the function with file name is difficult as this function is recursive function, which process the directories and files recursively. Kindly suggest me the alternative ways.

peeyush
  • 2,841
  • 3
  • 24
  • 43

2 Answers2

1

Move the catch() inside the body of the recursive method.

void readFilesRecursively(File dirOrFile){

    boolean successfullRead=false;
    for(; !successfullRead ;){
        try{
            ..........Read....
            successfullRead=true;
        }catch(java.io.FileNotFoundException ex){}
    }

}
Marinos An
  • 9,481
  • 6
  • 63
  • 96
1

Keep a list of files whose processing fails and add files in the list whenever u get the exception.

Once recursive call ends, check if list have any data, if yes, process them.

Pankaj
  • 5,132
  • 3
  • 28
  • 37