Using jdk7 , I am trying to use the java.nio.file.Files class to move an empty directory, say Bar , to another empty directory, say Foo
Path source = Paths.get("Bar"); Path target = Paths.get("Foo"); try { Files.move( source, target, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { e.printStackTrace(); }
After executing this piece of code, I expected the Bar directory to be in the Foo directory ( ...\Foo\Bar ). Instead it is not. And here is the kicker, he was also removed. In addition, no exceptions were selected .
Am I doing it wrong?
Note
I am looking for a jdk7 solution. I am also studying the problem, but I decided that I would see if there was anyone else playing with jdk7.
EDIT
In addition to the accepted answer, here is another solution
Path source = Paths.get("Bar"); Path target = Paths.get("Foo"); try { Files.move( source, target.resolve(source.getFileName()), StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { e.printStackTrace(); }
source share