I am in the middle of automating a series of actions that we do a lot in order to gain some time. This involves moving files around and starting some batches.
In this particular situation, I am trying to copy a file from one location to another location. All works fine, until I try to use the ATOMIC_MOVE
copy option. This is my code:
private void copyToDropFolder(Datafile datafile, String company) throws IOException{
Path datafilePath = datafile.getDataPath();
String dropFolder = locations.getLocationFor("default");
Path dropPath = Paths.get(dropFolder, company.toUpperCase(),locations.getLocationFor("drop"), datafile.getFileName());
Files.copy(datafilePath, dropPath, StandardCopyOption.ATOMIC_MOVE);
}
I have checked and resolved the locations of datafilePath and dropPath, they are both valid. I have tried with the other 2 standard copy options, and the program runs fine. It is only for ATOMIC_MOVE
that I get an UnsupportedOperationException
. It is not that I absolutely need that specific option, but I am curious why I wouldn't work. I cant really find any other reports on this issue. I am doing this on a Windows 7 machine.
Am I missing something? Or is the ATOMIC_MOVE
just not supported?
As API says, ATOMIC_MOVE
is not supported for copy()
, but for move()
only.
ATOMIC_MOVE
is for moving operations, not copying operations.
On the other hand, you can create so-called "hard links" using Files.createLink()
. There is also createSymbolicLink()
but this is probably not what you want here.
And of course, .createLink()
will only work if the source and destination paths are on the same filesystem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With