Reputation: 45
How to move one folder from one location to another location ?
Here is sample code what i did but here it is showing java.nio.file.NoSuchFileException
I am using this Package:
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;
Path path1 = FileSystems.getDefault().getPath("D:\\VFSImagecomp\\compressed\\");
Path path2 = FileSystems.getDefault().getPath("D:\\destinitionFile\\");
Files.move(path1, path2, StandardCopyOption.REPLACE_EXISTING);
Here i am trying to move the compressed folder into destinitionFile Folder.But it is not working .Can you Please suggest Me?
Upvotes: 1
Views: 2420
Reputation: 9331
You need to specify the name of your destination otherwise it will replace your parent
folder instead (Since you are using REPLACE_EXISTING
)
Path path1 = FileSystems.getDefault().getPath("D:\\VFSImagecomp\\compressed");
Path path2 = FileSystems.getDefault().getPath("D:\\destinitionFile\\myNewDirectory");
If you want to keep the same name then:
Path path2 = FileSystems.getDefault().getPath("D:\\destinitionFile\\compressed");
Upvotes: 2