0

The task is to create a new xml file from an old and the new file must have the same permissions as the old.

I tried

    newfile.setExecutable(oldfile.canExecute());
    newfile.setReadable(oldfile.canWrite());
    newfile.setWritable(oldfile.canRead());

but the result is old file "rw-rw-r--" and new file "rw-rw-rw-"

I also tried

    Path temp = Paths.get(path + FILE_NAME);
            Set<PosixFilePermission> set = 
    Files.getPosixFilePermissions(temp);
            System.out.println("Permissions  : " + 
    PosixFilePermissions.toString(set));

but I get

Exception in thread "main" java.lang.UnsupportedOperationException
    at sun.nio.fs.WindowsFileSystemProvider.readAttributes(Unknown Source)
    at java.nio.file.Files.readAttributes(Unknown Source)
    at com.company.product.loglevel.update_xxx(loglevel.java:xxx)
    at com.company.product.logging.loglevel.main(loglevel.java:xxx)

What am I doing wrong? Using Java 1.8

Brian
  • 307
  • 2
  • 15
  • have you tried this? https://stackoverflow.com/questions/664432/how-do-i-programmatically-change-file-permissions – JamieT Apr 10 '19 at 22:03
  • Yes I read through that post already but it's focus is on setting permissions. I don't see anywhere in there how to get the permissions of the old file. Maybe I'm missing it. – Brian Apr 10 '19 at 22:08
  • I just read it again and I noticed this "This method can only be used on POSIX file system, this means you cannot call it on Windows system." So that explains why I'm not getting the old file's permissions on windows. I just ran it on Linux and I get no error so I'm going to go from there. – Brian Apr 10 '19 at 22:18

0 Answers0