赞
踩
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.
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。