Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting specified file

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?

like image 959
Fran Avatar asked Jul 22 '15 14:07

Fran


Video Answer


1 Answers

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.

like image 82
vefthym Avatar answered Sep 28 '22 00:09

vefthym