Continue with @Andrew's answer
If we use only Files.move(src, dst, StandardCopyOption.REPLACE_EXISTING);
then it will delete source directory because we only provide a directory path not an absolute path of a particular file. So it will also delete a source directory when operation will be done.
Let's say source path is /opt/src
which contains a csv files and destination path is /opt/dst
and I want to move all files from src
to dst
and I'm using Files.move(src, dst, StandardCopyOption.REPLACE_EXISTING);
this then it will move all the files to dst
but it will delete a src
directory after moving all files because we didn't provide an absolute path of a each file for src
as well as dst
. We should have to provide src
path like /opt/src/foo.csv
and dst
path like /opt/dst/foo.csv
then and then it will not delete a source directory.
DirectoryStream
used to iterate over the entries in a directory. A directory stream allows for the convenient use of the for-each construct to iterate over a directory. So we get an absolute path for src
and we use resolve
method for resolving an absolute path for dst
.
Please refer DirectoryStream for more information.