6

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

Sandy
  • 2,253
  • 6
  • 24
  • 33

2 Answers2

3

In java7 - You can do the following

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

I have not tested this code. Hope it helps!!

Ouney
  • 1,164
  • 1
  • 10
  • 22
0

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

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

Hope it can help.

Bibs0u67
  • 106
  • 5