Java file copy - how to inherit destination directory permissions

When I copy a file from the source folder to the destination folder, the destination folder permissions are not inherited by the newly copied file. is there a way in Java where copying a file to a destination inherits the permissions of the destination folder?

+3


source to share


2 answers


In java7 - You can do the following

Files.copy(source, target, StandardCopyOption.COPY_ATTRIBUTES)



I have not tested this code. Hope this helps!

+2


source


Using Files.Copy works great and I tested this code where renameTo () or FileInput / OutputStream code didn't work.

Try it without StandardCopyOption and the permissions on the destination folder are automatically inherited like this: Files.copy(source.toPath(), destination.toPath());



Hope this helps.

0


source







All Articles