Good afternoon
Below is a method that I use to read certain files in a folder. The problem is this. If the folder has 50 files (or 60, or 70, or 80 ...) and the method is reading a "defective" file (one of the files that fall in Exeception
), the method locks on that file and does not consume the files. others. I would like that when entering a exception
, the stream would continue, and then return to that file. If it is OK, it consumes, if not, jump back to the others.
public static String lerPasta() throws FileNotFoundException{
String texto = null;
try{
FileFilter filter = new FileFilter() {
public boolean accept(File file) {
return file.getName().endsWith(".XML");
}
};
File dir = new File(diretorioIn);
File[] files = dir.listFiles(filter);
for(i = 0; i < files.length ; i++){
Scanner s = new Scanner(new File(files[i].toString()), "UTF-8");
texto = s.useDelimiter("\A").next();
System.out.println(ZonedDateTime.now(fusoHorarioDeSaoPaulo)+"VALOR DE I" +i);
verificaTipoXML(files[i].toString().substring(diretorioIn.length()));
System.out.println(ZonedDateTime.now(fusoHorarioDeSaoPaulo)+" verificaTipoXML:files[i].toString(): "+files[i].toString());
System.out.println(ZonedDateTime.now(fusoHorarioDeSaoPaulo)+" lerPasta():" + files[i].toString());
System.out.println(ZonedDateTime.now(fusoHorarioDeSaoPaulo)+" verificaTipoXML():" + files[i].toString().substring(diretorioIn.length()+0));
deleta = files[i].toString();
//+1
deleta2 = files[i].toString().substring(diretorioIn.length());
deletar = files[i];
System.out.println(ZonedDateTime.now(fusoHorarioDeSaoPaulo)+" deleta:"+deleta2);
nomegerado = files[i].toString().substring(diretorioIn.length()+3);
System.out.println(ZonedDateTime.now(fusoHorarioDeSaoPaulo)+" GLOBAL:nomegerado:" + nomegerado);
s.close();
}
}catch(FileNotFoundException e){
System.out.println(ZonedDateTime.now(fusoHorarioDeSaoPaulo)+"lerPasta():ERRO: FileNotFoundException : Tentando novamente ...");
}
catch(NoSuchElementException e){
System.out.println(ZonedDateTime.now(fusoHorarioDeSaoPaulo)+"lerPasta():ERRO: NoSuchElementException : Tentando novamente ...");
}
return texto;
}