Java.nio.file.AccessDeniedException when using Files.move ()

I do java.nio.file.Files.move(path, path.resolveSibling("newfilename"))to rename a directory in Windows 7.

But I get 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 causes this? I am using Java 7. The
target path does not exist before the call Files.move().

UPDATE

From javadoc :

When moving a directory requires that its entries be moved then this method fails
(by throwing an IOException).

My directory is not empty and contains regular files, so maybe this is the reason it cannot be used here? I'm having trouble understanding what “requires his records to be migrated”. When is this so?

+4
source share
7 answers

Windows, , .

+2

, Windows. Windows Explorer .

+1

, , , , ? ", ". ?

( ), . , Files.move(), , .

, , .

0

, Files.move(path1, path2, StandardCopyOption.ATOMIC_MOVE), , - .

0

, , 2 , , - .

, " " , .

0

. , Windows.

Windows , , .

: enter image description here

Windows, .

0

, , .

0

Source: https://habr.com/ru/post/1535927/


All Articles