Getting “java.nio.file.AccessDeniedException” when trying to write to a folder

后端 未结 4 721
感情败类
感情败类 2020-12-01 20:34

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

4条回答
  •  余生分开走
    2020-12-01 20:59

    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);
    

提交回复
热议问题