I have a problem while deleting files from img directory using org.apache.commons.io.FileUtils. I am using this code:
File dir = new File(".\\img");
FileFilter fileFilter = new WildcardFileFilter(userId + ".*");
File[] files = dir.listFiles(fileFilter);
System.out.println("files found: " + files.length);
for (int i = 0; i < files.length; i++) {
boolean success = FileUtils.deleteQuietly(files[i]);
System.out.println(files[i] + " delete result = " + success);
}
}
Actually the code is using for replacing image files existed in img directory with the new one. I need to delete all previously existed files which names are n.*, with the new file e.g. n.png. If I am trying to delete image files, I get false value for the variable success and the files are not deleted. But not image files e.g. *.abc; *.acd; *.acdc etc. are deleted succesfully. What is the case of this issue?
Try this:
java.nio.file.Files.delete(files[i].toPath());
And see what exception will be thrown.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With