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.
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.
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);
}