Difference between Files#delete(Path) and File#delete()

Premraj ipremraj11 at gmail.com
Wed Aug 29 10:15:05 UTC 2012


Hi all,

I'm not sure whether this is the right place for this question but if in
case its not please direct me to the correct forum.

I was trying to shift from old file API to NIO API (using JDK 7 update 6)
but I found that on Windows (I have Windows 7) platform if I have read only
file then File#delete() call will delete the file while Files#delete(Path)
fails with exception (java.nio.file.AccessDeniedException), I'm not sure
whether this is known issue but since Files#delete(Path) offers better
error handling I would like to use Files#delete(Path).

My question is - Is there any workaround for this problem in NIO API or
should I stick to old File API because of this. Also I was curios why
Files#delete(Path) throws exception but File#delete() executes successfully.

PS: I asked this question[1] on stackoverflow but did not get any good
response.

1.
http://stackoverflow.com/questions/12139482/difference-between-filesdeletepath-and-filedelete/

-- Premraj



More information about the core-libs-dev mailing list