I'm using the following method to moves files from one folder(source) to another(destination). I have added a check to see if the file exists which is returning true, but still the file is not moving to the destination.
Here the source paths are:
C:\App_v10.4\RAP009.jrxml and C:\App_v10.4\RAP009.jasper
Destination :
C:\Users\Avijit\Desktop\RAP009.jrxml and C:\Users\Avijit\Desktop\RAP009.jasper
private void moveFile(List<String> source, String destination)
throws IOException {
if (null != source && !source.isEmpty()) {
for (String path : source) {
try {
File file = new File(path);
System.out.println(path);
System.out.println("File :" + file.exists());
System.out.println(new File(destination + file.getName()));
System.out.println(file.getCanonicalPath());
System.out.println(file.getAbsolutePath());
System.out.println(file.getPath());
if (file.renameTo(new File(destination + file.getName()))) {
System.out.println("File is moved successful!");
} else {
System.out.println("File has failed to move!");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Console O/P :
C:\App_v10.4\RAP009.jrxml
File :true
C:\Users\Avijit\Desktop\RAP009.jrxml
C:\App_v10.4\RAP009.jrxml
C:\App_v10.4\RAP009.jrxml
C:\App_v10.4\RAP009.jrxml
File has failed to move!
C:\App_v10.4\RAP009.jasper
File :true
C:\Users\Avijit\Desktop\RAP009.jasper
C:\App_v10.4\RAP009.jasper
C:\App_v10.4\RAP009.jasper
C:\App_v10.4\RAP009.jasper
File has failed to move!