Reputation: 11
I am trying to move the failed files to different directory. Currently, everything seems to work fine except that it creates a file(just plan file without extension). I want directory to be created and all the failed files to go into that directory. Here is my code below. what seems to be wrong?
Path source= Paths.get(("C:/Users/aa/Desktop/whatever" + originalfilename));
Path target = Paths.get("C:/Users/aa/Desktop/Directory1 " );
Files.move(source,target, REPLACE_EXISTING, COPY_ATTRIBUTES);
PS: originalfilename(String) are the filenames of the directory. If I execute it, it gives a file Directory1, but it's not a directory folder.
Upvotes: 1
Views: 123
Reputation: 38152
From the JavaDoc:
Path source = ...
Path newdir = ...
Files.move(source, newdir.resolve(source.getFileName()), REPLACE_EXISTING);
Upvotes: 0
Reputation: 11900
Try this code instead:
File yourFile=new File("D:\\irectory\\Afile.txt");
if(yourFile.renameTo(new File("D:\\irectory\\" + yourFile.getName())))
System.out.println("File moved succesfully bro!");
else
System.out.println("Errors moving the file.");
Upvotes: 2