Fran
Fran

Reputation: 577

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?

Upvotes: 5

Views: 124

Answers (1)

vefthym
vefthym

Reputation: 7462

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.

Upvotes: 6

Related Questions