1

I tried

Path path = Paths.get("/home/HP-124/Desktop/testDir2");
String newOwn = "jack";
Process process = Runtime.getRuntime().exec("chown -R" +newOwn+ path);

and

File sourceFolder = new File("/home/HP-124/Desktop/testDir2");
UserPrincipal SourceFolderOwner = 
      java.nio.file.Files.getOwner(sourceFolder.toPath());
Files.setOwner(path,DestinationFolderOw);

Error

Exception in thread "main" java.nio.file.FileSystemException: /home/p.szwajkowsk/Desktop/testDir2: Operation not permitted
    at sun.nio.fs.UnixException.translateToIOException(UnixException.java:91)
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
    at sun.nio.fs.UnixFileAttributeViews$Posix.setOwners(UnixFileAttributeViews.java:252)
    at sun.nio.fs.UnixFileAttributeViews$Posix.setOwner(UnixFileAttributeViews.java:274)
    at sun.nio.fs.FileOwnerAttributeViewImpl.setOwner(FileOwnerAttributeViewImpl.java:100)
    at java.nio.file.Files.setOwner(Files.java:2127)
    at com.javatutorialhq.tutorial.FilePermissions.main(FilePermissions.java:39)
pirho
  • 11,565
  • 12
  • 43
  • 70
  • Do you get any error when you try or does it just silently ignore? If get error please attach it. – pirho Dec 07 '17 at 11:00

0 Answers0