I have one particular file that, even it's been written by my own process, can't be deleted:
Files.copy(source, destination, StandardCopyOption.REPLACE_EXISTING);
Files.deleteIfExists(destination);
No matter what I try, I always get:
java.nio.file.AccessDeniedException: C:\ProgramData\FAForever\bin\BsSndRpt.exe
at sun.nio.fs.WindowsException.translateToIOException(Unknown Source) ~[na:1.8.0_45]
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source) ~[na:1.8.0_45]
at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source) ~[na:1.8.0_45]
at sun.nio.fs.WindowsFileSystemProvider.implDelete(Unknown Source) ~[na:1.8.0_45]
at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(Unknown Source) ~[na:1.8.0_45]
at java.nio.file.Files.deleteIfExists(Unknown Source) ~[na:1.8.0_45]
All other files, with EXACTLY the same user/group permission and owner, don't have this problem. And no, the file isn't opened, since I just copied it there.
How can this possibly be? How could I find out? (ProcMon only gave "BUFFER OVERFLOW" but no access violation or so) How can I fix it?
You need to change the file properties to be not as 'Read only'
Go to the file itself using: Windows Explorer -> right click -> Properties.
Change the file permissions in the bottom of the dialog.