I'm trying to copy files using java. I have an arraylist of File objects that need copying but when the actual copy takes place the destination folder gets turned into a file and nothing is copied
System.out.println("Dest: " + destPath.toString());
ArrayList<File> fileList = listFiles(sourceDir);
for (File file : fileList) {
Path sourcePath = Paths.get(file.getPath());
System.out.print("\r\nSource: " + sourcePath.toString());
CopyOption[] options = new CopyOption[] {
StandardCopyOption.REPLACE_EXISTING,
StandardCopyOption.COPY_ATTRIBUTES
};
try {
Files.copy(sourcePath, destPath, options);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
The printed paths are: Dest: C:\Users\Ceri\Desktop\New folder (2)
Source: C:\Users\Ceri\Desktop\New folder\Blue cave floor.png Source: C:\Users\Ceri\Desktop\New folder\New Text Document.txt
Basically when i'm doing is trying to get a list of all changed/new files in a directory - specified by a text field - and copy them to another directory - again specified by a text field
the listFiles method returns the files