For some reason I keep getting java.nio.file.AccessDeniedException
every time I try to write to a folder on my computer using a java webapp on Tomcat. This fold
Ok it turns out I was doing something stupid. I hadn't appended the new file name to the path.
I had
rootDirectory = "C:\\safesite_documents"
but it should have been
rootDirectory = "C:\\safesite_documents\\newFile.jpg"
Sorry it was a stupid mistake as always.
I was getting the same error when trying to copy a file. Closing a channel associated with the target file solved the problem.
Path destFile = Paths.get("dest file");
SeekableByteChannel destFileChannel = Files.newByteChannel(destFile);
//...
destFileChannel.close(); //removing this will throw java.nio.file.AccessDeniedException:
Files.copy(Paths.get("source file"), destFile);
Not the answer for this question
I got this exception when trying to delete a folder where i deleted the file inside.
Example:
createFolder("folder");
createFile("folder/file");
deleteFile("folder/file");
deleteFolder("folder"); // error here
While deleteFile("folder/file");
returned that it was deleted, the folder will only be considered empty after the program restart.
On some operating systems it may not be possible to remove a file when it is open and in use by this Java virtual machine or other programs.
https://docs.oracle.com/javase/8/docs/api/java/nio/file/Files.html#delete-java.nio.file.Path-
Explanation from dhke
Delete .android folder cache files, Also delete the build folder manually from a directory and open android studio and run again.