当前位置:   article > 正文

java files.move,使用Files.move()时java.nio.file.AccessDeniedException

accessdeniedexception使用file归档时

I'm doing a java.nio.file.Files.move(path, path.resolveSibling("newfilename")) to rename a directory on windows 7.

But I'm getting the following exception:

java.nio.file.AccessDeniedException: oldfilename -> newfilename

at sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:83)

at sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)

at sun.nio.fs.WindowsFileCopy.move(WindowsFileCopy.java:387)

at sun.nio.fs.WindowsFileSystemProvider.move(WindowsFileSystemProvider.java:287)

at java.nio.file.Files.move(Files.java:1345)

What is causing this? I'm using Java 7.

The target path does not exist before the invocation of Files.move().

UPDATE

When moving a directory requires that its entries be moved then this method fails

(by throwing an IOException).

My directory is non-empty and contains regular files, so maybe that is the reason that it cannot be used here? I'm having problems understanding the "requires that its entries be moved" wording. When is this the case?

解决方案

I had this problem when the target directory was open in Windows Explorer. Closing Windows Explorer made it work.

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/325257
推荐阅读
相关标签
  

闽ICP备14008679号