Jump to content

dúvida apagar ficheiros em ciclo


caxinaswin
 Share

Recommended Posts

Boas tenho um conjunto de datas num ArrayList e queria apaga los quando accionado um evento gostaria de saber se esta é a forma correta porque me ta a dar alguns problemas

File newFile = null;
               for(int i = 0;i<Manager.Datas.size();i++)
               {
                newFile = new File(Manager.Datas.get(i) + ".txt");
                   newFile.delete();
                   Manager.Datas.remove(i);
               }
Link to comment
Share on other sites

Nao me parece...

Nao deves apagar valores de uma Lista dentro de um ciclo for crescente que é um iterador da mesma Lista...

Pergunta:

qual o valor de Manager.Datas.size() quando fazes Manager.Datas.remove(i); ?

Tenta antes um ciclo decrescente:

for(int i = Manager.Datas.size()-1 ;i>=0;i--) ....

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.