我试过
Path path = Paths.get("/home/HP-124/Desktop/testDir2");
String newOwn = "jack";
Process process = Runtime.getRuntime().exec("chown -R" +newOwn+ path);
和
File sourceFolder = new File("/home/HP-124/Desktop/testDir2");
UserPrincipal SourceFolderOwner =
java.nio.file.Files.getOwner(sourceFolder.toPath());
Files.setOwner(path,DestinationFolderOw);
错误
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)