I'm taking a look at the page labeled "Moving a File or Directory" at web page "docs.oracle.com/javase/tutorial/essential/io/move.html", in an attempt to learn some of the new features of
Java 1.7. This page describes the {Files.move()} method and says that it "takes a varargs argument" and describes as one possible argument "REPLACE_EXISTING--Performs the move even when the target file already exists." Doesn't that mean that if this argument is
not specified and the target file already exists, that the move should not occur?
That was my impression, so I wrote the code:
This code is designed to either move a file from one location to another (if the last argument is not a directory), or to move one or more files to a directory (if the last argument is a directory). Note that at no time do I specify argument "REPLACE_EXISTING"; on the other hand I do specify argument "ATOMIC_MOVE", because if there's some problem along the way I don't want pieces of my files existing anywhere.
This program works just fine as long as moving the files would not overwrite any other files. But when I create two small files, call them "Uvw.java" and "Xyz.java", and create directory "Zqj", and copy "Uvw.java" into "Zqj", and execute "java Move Uvw.java Xyz.java Zqj", the copy of "Uvw.java" in "Zqj" gets overwritten! Can anyone tell me why this is happening? Shouldn't {AccessDeniedException} get thrown when I try to move "Uvw.java" to the "Zqj" directory?
Kevin S