0

I'm trying to delete files using a for-loop.

for(int i = 0; i < 3; i++) {

   String pathName = "test" + i + ".csv";
   boolean success = (new File(pathName)).delete();

}

But this code deletes only the first file, but not the other ones.

Anish B.
  • 9,111
  • 3
  • 21
  • 41
jumpy
  • 73
  • 7

1 Answers1

0

This worked for me. Maybe the path where your files are located is incorrect.

for(int i = 1; i <= 3; i++) {
    boolean success = (new File("C:\\Users\\Suppada-Aide\\Desktop\\test"+i+".txt")).delete();
    System.out.println(success);
}
Hasho
  • 79
  • 1
  • 6