I'm trying to delete files but it isn't working or I'm missing something. Here is a little test I'm doing:
private void deleteFromDir(String filename) {
String path = "./test/pacientes/" + filename + ".tds";
File f = new File(path);
System.out.println("Abs path " + f.getAbsolutePath());
System.out.println("Exist " + f.exists());
System.out.println("Filename " + f.getName());
System.out.println("Delete " + f.delete());
}
And the system prints:
Abs path C:\Users\XXXX\Documents\PAI\TSoft.\test\pacientes\John Smith.tds
Exist true
Filename John Smith.tds
Delete false
And of course isn't deleting the file, why? How can I make it work?
Perhaps, you do not have the permission to delete this file. You can use the Files.delete() method, which throws an IOException, in case something goes wrong, to see what the real problem is.
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